我在laravel 5.1中使用并希望使用artisan命令在特定时间重试失败的作业。我失败的所有作业都存储在failed_jobs表中。
namespace App\Console\Commands;
use Illuminate\Console\Command;
class QueueRetryFailedJobs extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'queue:retryFailedJobs';
/**
* 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]);
//echo $value->id;
});
} else {
$this->error('No failed jobs.');
}
}
}
它会打印正确的ID,但$this->call('queue:retry', ['id' => $value->id]);
会出现以下错误。
[ErrorException]
Invalid argument supplied for foreach()
有任何建议吗?
答案 0 :(得分:0)
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class QueueRetryFailedJobs extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'queue:retryFailedJobs';
/**
* 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();
$idArray = array();
if (! empty($failed)) {
for($i=0;$i<sizeof($failed);$i++){
$idArray[] = $failed[$i]->id;
}
$this->call('queue:retry', ['id' => $idArray]);
} else {
$this->error('No failed jobs.');
}
}
}