File tree Expand file tree Collapse file tree 3 files changed +66
-2
lines changed
Expand file tree Collapse file tree 3 files changed +66
-2
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Doppar \Queue \Commands ;
4+
5+ use Phaseolies \Console \Schedule \Command ;
6+ use Doppar \Queue \QueueManager ;
7+ use Doppar \Queue \Models \FailedJob ;
8+
9+ class QueueFlushCommand extends Command
10+ {
11+ /**
12+ * The name of the console command.
13+ *
14+ * @var string
15+ */
16+ protected $ name = 'queue:flush {--id=} ' ;
17+
18+ /**
19+ * The command description.
20+ *
21+ * @var string
22+ */
23+ protected $ description = 'Delete failed job(s) by ID or all if no ID is provided ' ;
24+
25+ /**
26+ * Execute the console command
27+ * Example: php pool queue:flush --id=1
28+ *
29+ * @return int
30+ */
31+ protected function handle (): int
32+ {
33+ $ id = $ this ->option ('id ' );
34+
35+ if ($ id ) {
36+ return $ this ->flushJobById ($ id );
37+ }
38+
39+ FailedJob::query ()
40+ ->cursor (function (FailedJob $ failedJob ) {
41+ $ failedJob ->delete ();
42+ $ this ->info ("✔ Job with ID {$ failedJob ->id } has been deleted. " );
43+ });
44+
45+ return Command::SUCCESS ;
46+ }
47+
48+ protected function flushJobById (int $ id ): int
49+ {
50+ $ failedJob = FailedJob::find ($ id );
51+
52+ if (!$ failedJob ) {
53+ $ this ->error ("Failed job with ID {$ id } not found. " );
54+ return Command::FAILURE ;
55+ }
56+
57+ $ failedJob ->delete ();
58+ $ this ->info ("✔ Job with ID {$ failedJob ->id } has been deleted. " );
59+
60+ return Command::SUCCESS ;
61+ }
62+ }
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ abstract class Job implements JobInterface
1111 *
1212 * @var int
1313 */
14- public $ tries = 3 ;
14+ public $ tries = 1 ;
1515
1616 /**
1717 * The number of seconds to wait before retrying the job.
Original file line number Diff line number Diff line change 33namespace Doppar \Queue ;
44
55use Doppar \Queue \Commands \MakeJobCommand ;
6+ use Doppar \Queue \Commands \QueueFlushCommand ;
67use Phaseolies \Providers \ServiceProvider ;
78use Doppar \Queue \QueueManager ;
89use Doppar \Queue \Commands \QueueRunCommand ;
@@ -36,7 +37,8 @@ public function boot(): void
3637 $ this ->commands ([
3738 QueueRunCommand::class,
3839 QueueRetryCommand::class,
39- MakeJobCommand::class
40+ MakeJobCommand::class,
41+ QueueFlushCommand::class
4042 ]);
4143 }
4244}
You can’t perform that action at this time.
0 commit comments