Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Added range option to queue:retry command #33627

Merged
merged 2 commits into from
Jul 23, 2020
Merged
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
29 changes: 27 additions & 2 deletions src/Illuminate/Queue/Console/RetryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class RetryCommand extends Command
*
* @var string
*/
protected $signature = 'queue:retry {id* : The ID of the failed job or "all" to retry all jobs}';
protected $signature = 'queue:retry
{id?* : The ID of the failed job or "all" to retry all jobs}
{--range=* : Range of job IDs (numeric) to be retried}';

/**
* The console command description.
Expand Down Expand Up @@ -53,7 +55,30 @@ protected function getJobIds()
$ids = (array) $this->argument('id');

if (count($ids) === 1 && $ids[0] === 'all') {
$ids = Arr::pluck($this->laravel['queue.failer']->all(), 'id');
return Arr::pluck($this->laravel['queue.failer']->all(), 'id');
}

if ($ranges = (array) $this->option('range')) {
$ids = array_merge($ids, $this->getJobIdsByRanges($ranges));
}

return array_values(array_filter(array_unique($ids)));
}

/**
* Get the job IDs ranges, if applicable.
*
* @param array $ranges
* @return array
*/
protected function getJobIdsByRanges(array $ranges)
{
$ids = [];

foreach ($ranges as $range) {
if (preg_match('/^[0-9]+\-[0-9]+$/', $range)) {
$ids = array_merge($ids, range(...explode('-', $range)));
}
}

return $ids;
Expand Down