I wrote an Express application which I would like to scale using pm2. This express app performs a couple jobs which I only need to execute once. When I am going to start multiple instances of my jobs using pm2 I assume that it will also run the defined jobs multiple times.
So how can I make my application aware that only one instance has to run specific code portions?
Code example:
agenda.every('1 hours', 'refreshProfiles')
You should be able to use this snippet, see docs
if (process.env.NODE_APP_INSTANCE === 0) {
agenda.every('1 hours', 'refreshProfiles')
}
Most helpful comment
You should be able to use this snippet, see docs