I recently setup a Laravel Queue system. The basics are a cronjob calls a command which adds jobs to a queue and calls a second command which sends an email.
The sy
I achieved the result without any service monitor or third party software. The solution is working fine but I am not sure if it is the best way.
Solution
Just run cli command in the following way in your function.
use Illuminate\Console\Command;
public function callQueue()
{
$restart = 'php-cli ' . base_path() . '/artisan queue:restart > /dev/null & echo $!';
$work = 'php-cli ' . base_path() . '/artisan queue:work --timeout=0 --sleep=5 --tries=3 > /dev/null & echo $!';
exec($restart);
exec($work);
}
$job = (new jobName())->delay(Carbon::now()->addSeconds(5));
dispatch($job);
Reason
The reason I have used these two commands is because the command associated with $restart
prevent having any memory issue according to a comment in this answer
and the command associated with $work
ensures that the command is successfully executed before the job.