When I run
NODE_ENV=production slc run
loopback will automatically start workers for each CPU core.
I want to run some code only once, but every worker runs it. How can I check what worker it is currently running in?
I noticed it is using strong-supervisor behind the scenes to do its magic.
This is how I solved it:
var cluster = require('cluster');
if (cluster.isMaster || (cluster.isWorker && cluster.worker.id == '1'))) {
//Do stuff
}
Read more about cluster here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With