lundi 22 août 2016

Queue:retry command from other artisan command in laravel

I am usin laravel 5.1 and want to retry failed jobs at the specific time using artisan commands. All my failed jobs are stored in 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.');
        }
    }

}

It prints correct ids but $this->call('queue:retry', ['id' => $value->id]); gives following error.

[ErrorException]
 Invalid argument supplied for foreach()

Any Suggestion ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire