diff --git a/src/Commands/QueueFlushCommand.php b/src/Commands/QueueFlushCommand.php new file mode 100644 index 0000000..6d3e058 --- /dev/null +++ b/src/Commands/QueueFlushCommand.php @@ -0,0 +1,62 @@ +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; + } +} diff --git a/src/Job.php b/src/Job.php index e9902e8..d8032f8 100644 --- a/src/Job.php +++ b/src/Job.php @@ -11,7 +11,7 @@ abstract class Job implements JobInterface * * @var int */ - public $tries = 3; + public $tries = 1; /** * The number of seconds to wait before retrying the job. diff --git a/src/QueueServiceProvider.php b/src/QueueServiceProvider.php index d0234a8..dec7060 100644 --- a/src/QueueServiceProvider.php +++ b/src/QueueServiceProvider.php @@ -3,6 +3,7 @@ namespace Doppar\Queue; use Doppar\Queue\Commands\MakeJobCommand; +use Doppar\Queue\Commands\QueueFlushCommand; use Phaseolies\Providers\ServiceProvider; use Doppar\Queue\QueueManager; use Doppar\Queue\Commands\QueueRunCommand; @@ -36,7 +37,8 @@ public function boot(): void $this->commands([ QueueRunCommand::class, QueueRetryCommand::class, - MakeJobCommand::class + MakeJobCommand::class, + QueueFlushCommand::class ]); } }