How to run Cron Job in Node.js application that uses cluster module?

后端 未结 5 1180
隐瞒了意图╮
隐瞒了意图╮ 2021-02-01 04:02

I\'m using node-cron module for scheduling tasks in Node.js application. I also want run the application in several processes using core cluster module.

Running applica

5条回答
  •  故里飘歌
    2021-02-01 04:30

    I think you can use the node cluster module, and there you can write your code to run in the master cluster only

    const cluster = require('cluster');
    
    if (cluster.isMaster) {
         // Write your code which you want to execute in the master cluster only
    }
    

    This is a node way to handle cluster, of course, you can use any tool like pm2 to handle this.

提交回复
热议问题