Place these in your App/Console/Commands
directory, then add the classes to the $commands
property in your App/Console/Kernel.php
class.
Created
November 11, 2015 05:32
-
-
Save JacobBennett/d705bf468ac1a7995a2a to your computer and use it in GitHub Desktop.
Laravel Queue:Retry-Multiple and Queue:Retry-All
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 | |
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.'); | |
} | |
} | |
} |
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 | |
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