来自 laravel 中其他 artisan 命令的 Queue:retry 命令

Queue:retry command from other artisan command in laravel

我正在使用 laravel 5.1 并想在特定时间使用 artisan 命令重试失败的作业。我所有失败的作业都存储在 failed_jobs table.

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()

有什么建议吗?

<?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.');
        }
    }

}