How to keep Laravel Queue system running on server

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

    For those who are already running NodeJS on their production environments. I use PM2 to manage app processes.

    # install
    npm install -g pm2
    
    # in project dir with your CI or dev setup tool 
    # --name gives task a name so that you can later manage it
    # -- delimits arguments that get passed to the script
    pm2 start artisan --interpreter php --name queue-worker -- queue:work --daemon
    

    I use Vagrant in development and setup NodeJS and this process using only inline vagrant scripts.

    When you use PM2 in development you can use one of the many watchers to manage the restart. Simply run pm2 restart queue-worker when you pick up a change. In production I don't recommend this approach, rather opt for a build tool that can follow this process.

    # 1. stop pm task to ensure that no unexpected behaviour occurs during build
    pm2 stop queue-worker
    # 2. do your build tasks
    ...
    # 3. restart queue so that it loads the new code
    pm2 restart queue-worker
    

提交回复
热议问题