Skip to content

Instantly share code, notes, and snippets.

@krogla
Forked from JacobBennett/QueueRetryAllCommand.php
Created November 14, 2017 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krogla/54f1f5ca424239dde6125b8afc4bd7c4 to your computer and use it in GitHub Desktop.
Save krogla/54f1f5ca424239dde6125b8afc4bd7c4 to your computer and use it in GitHub Desktop.
Laravel Queue:Retry-Multiple and Queue:Retry-All

Place these in your App/Console/Commands directory, then add the classes to the $commands property in your App/Console/Kernel.php class.

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class RetryAllCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'queue:retry-all';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Release all failed-jobs onto the queue.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$failed = $this->laravel['queue.failer']->all();
if (! empty($failed)) {
collect($failed)->each(function($value) {
$this->call('queue:retry', ['id' => $value->id]);
});
} else {
$this->error('No failed jobs.');
}
}
}
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class RetryMultipleCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'queue:retry-multiple
{ids : the ids of the failed-jobs you would like released (separate multiple ids with a comma)}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Release multiple failed-jobs onto the queue.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
collect($this->parseIds())->each(function($id) {
$this->call('queue:retry', ['id' => $id]);
});
}
private function parseIds()
{
return explode(',', $this->argument('ids'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment