When I run
当我跑
NODE_ENV=production slc run
loopback will automatically start workers for each CPU core.
loopback将自动启动每个CPU核心的worker。
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.
我注意到它在幕后使用强大的监督者来实现它的魔力。
1 个解决方案
#1
2
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
阅读更多关于集群的信息
#1
2
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
阅读更多关于集群的信息