-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQueueFlushCommand.php
More file actions
62 lines (50 loc) · 1.37 KB
/
QueueFlushCommand.php
File metadata and controls
62 lines (50 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace Doppar\Queue\Commands;
use Phaseolies\Console\Schedule\Command;
use Doppar\Queue\QueueManager;
use Doppar\Queue\Models\FailedJob;
class QueueFlushCommand extends Command
{
/**
* The name of the console command.
*
* @var string
*/
protected $name = 'queue:flush {--id=}';
/**
* The command description.
*
* @var string
*/
protected $description = 'Delete failed job(s) by ID or all if no ID is provided';
/**
* Execute the console command
* Example: php pool queue:flush --id=1
*
* @return int
*/
protected function handle(): int
{
$id = $this->option('id');
if ($id) {
return $this->flushJobById($id);
}
FailedJob::query()
->cursor(function (FailedJob $failedJob) {
$failedJob->delete();
$this->info("✔ Job with ID {$failedJob->id} has been deleted.");
});
return Command::SUCCESS;
}
protected function flushJobById(int $id): int
{
$failedJob = FailedJob::find($id);
if (!$failedJob) {
$this->error("Failed job with ID {$id} not found.");
return Command::FAILURE;
}
$failedJob->delete();
$this->info("✔ Job with ID {$failedJob->id} has been deleted.");
return Command::SUCCESS;
}
}