Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/Commands/QueueFlushCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
}
}
2 changes: 1 addition & 1 deletion src/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion src/QueueServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,7 +37,8 @@ public function boot(): void
$this->commands([
QueueRunCommand::class,
QueueRetryCommand::class,
MakeJobCommand::class
MakeJobCommand::class,
QueueFlushCommand::class
]);
}
}
Loading