Skip to content

Instantly share code, notes, and snippets.

@vitorbari
Last active November 16, 2023 06:06
Show Gist options
  • Save vitorbari/0ed093cf336278311ec070ab22b3ec3d to your computer and use it in GitHub Desktop.
Save vitorbari/0ed093cf336278311ec070ab22b3ec3d to your computer and use it in GitHub Desktop.
Laravel 4.2 Queue Retry All Command
<?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);
}
}
@vitorbari
Copy link
Author

Put the file on directory app/commands;
Add to app/start/artisan.php:
Artisan::resolve('QueueRetryAllCommand');

@dandelionmood
Copy link

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