How to make a cron job with PM2

后端 未结 6 1113
隐瞒了意图╮
隐瞒了意图╮ 2020-12-23 14:25

I want to make a cron job to send mail every 15 minutes taking data from a database table. In node js I can make a cron job but through PM2 I don\'t understand where to plac

6条回答
  •  清歌不尽
    2020-12-23 14:39

    If you use PM2 ecosystem then in the config file add cron sequence to script param by wrapping it with single quotes. Somehow double quotes didn't work for me.

    module.exports = {
      apps : [{
        name        : "Send-mail",
        script      : "./sendMail.js --cron '*/15 * * * *'",
        watch       : true
      }]
    }
    

    alternatively (my preference)

    module.exports = {
      apps : [{
        name        : "Send-mail",
        script      : "./sendMail.js",
        cron_restart: "*/15 * * * *",
        watch       : true
      }]
    }
    

提交回复
热议问题