How to keep Laravel Queue system running on server

后端 未结 17 994
小鲜肉
小鲜肉 2020-11-28 02:23

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

17条回答
  •  离开以前
    2020-11-28 03:15

    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.

提交回复
热议问题