How to keep Laravel Queue system running on server

后端 未结 17 1006
小鲜肉
小鲜肉 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

    Since this was a Laravel-specific question, I thought I would suggest a Lravel-specific answer. Since you are already using cronjobs on this server, I would recommend that you set up the shell command as a recurring cronjob to always verify that the worker is running. You could either set up the shell command to run natively through cron on your server, or you could use the Laravel console kernel to manage the command and add logic, such as checking whether you already have a worker running and, if not, go ahead and start it back up.

    Depending on how often you need to run your command, you could do this as infrequently as once a week, or even once a minute. This would give you the ability to make sure that your workers are continuously running, without having to add any overhead to your server, such as Supervisor. Giving permissions to a 3rd party package like supervisor is ok if you trust it, but if you can avoid needing to rely on it, you may want to consider this approach instead.

    An example of using this to do what you want would be to have a cronjob that runs each hour. It would execute the following in sequential order from within a custom Laravel console command:

    \Artisan::call('queue:restart');

    \Artisan::call('queue:work --daemon');

    Note that this applies for older versions of Laravel (up to 5.3) but I haven't tested on newer versions.

提交回复
热议问题