Laravel 5 Run queue:work on laravel schedule

paranoid picture paranoid · Dec 24, 2018 · Viewed 9.8k times · Source

I have a schedule like this:

<?php

namespace App\Console;

use Illuminate\Support\Facades\Artisan;
use Illuminate\Console\Scheduling\Schedule;
protected function schedule(Schedule $schedule)
{
   Artisan::call('queue:work');
}

I add this on my cronjob:

* * * * * cd /var/www/html/my_script_address && php artisan schedule:run

Is it correct code? I am asking, because every minute run Artisan::call('queue:work').

Is it the best way?

Answer

Adam Martinez picture Adam Martinez · Jun 11, 2019

Your queue worker should be running on its own. You should use supervisor to make sure it stays running. However, if you must start the queue worker from the scheduler it is probably best to use queue:work --stop-when-empty