Last active
November 16, 2023 06:06
Laravel 4.2 Queue Retry All Command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Console\Command; | |
use Symfony\Component\Console\Input\InputArgument; | |
class QueueRetryAllCommand extends Command | |
{ | |
/** | |
* The console command name. | |
* | |
* @var string | |
*/ | |
protected $name = 'queue:retry-all'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Retry all failed queue jobs'; | |
/** | |
* Execute the console command. | |
* | |
* @return void | |
*/ | |
public function fire() | |
{ | |
$jobs = $this->laravel['queue.failer']->all(); | |
if (count($jobs)) { | |
foreach ($jobs as $failed) { | |
$failed->payload = $this->resetAttempts($failed->payload); | |
$this->laravel['queue']->connection($failed->connection)->pushRaw($failed->payload, $failed->queue); | |
$this->laravel['queue.failer']->forget($failed->id); | |
$this->info('The failed job (ID: ' . $failed->id . ') has been pushed back onto the queue!'); | |
} | |
} else { | |
$this->error('No failed jobs!'); | |
} | |
} | |
/** | |
* Reset the payload attempts. | |
* | |
* @param string $payload | |
* @return string | |
*/ | |
protected function resetAttempts($payload) | |
{ | |
$payload = json_decode($payload, true); | |
if (isset($payload['attempts'])) $payload['attempts'] = 0; | |
return json_encode($payload); | |
} | |
} |
Thanks, that's exactly what I needed :) !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put the file on directory app/commands;
Add to app/start/artisan.php:
Artisan::resolve('QueueRetryAllCommand');