I have a NestJS server working in cluster mode on ec2 instance using pm2.
I have successfully set up cron jobs executing only one time in the cluster mode by starting the server with multiple name configurations using the name of the pm2 process.
{
"apps":[
{
"script":"dist/main.js",
"instances": "1",
"exec_mode": "cluster",
"name":"queue"
},
{
"script":"dist/main.js",
"instances": "1",
"exec_mode": "cluster",
"name":"coco"
}
]
}
But I want to know how to handle this case when multiple instances are behind the load balancer. As the jobs are scheduled on each instance and executed multiple times with the same data from the remote database.
Any help would be appreciated.