It looks like each process in a Strongloop cluster is considered a worker, and therefore if you use a tool like node-scheduler that schedules jobs and you have multiple workers, the job is executed multiple times.
Ideally I'd be able to do something like:
var cluster = require('cluster');
if (cluster.isMaster) {
// execute code
}
Since this doesn't seem to be possible, I wonder if there is a way to get a list of all worker or process IDs from inside the node app so that I can do this same sort of thing with one worker? This will need to be something dynamic, as cluster.worker.id
does not appear to be a reliable way to do this since the worker IDs are unpredictable.
Ideas?
答案 0 :(得分:1)
“strongloop cluster”不属于它,它是一个节点集群:https://nodejs.org/dist/latest-v6.x/docs/api/cluster.html
不存在这样的API,它对你没有帮助,你需要实现某种共识算法来选择其中一个(动态,工人可以死掉,更换/重新启动)一组工人作为“单身人士”
将系统编写为微服务,如果需要单例任务运行器,将其作为服务,并以1的簇大小运行它。
这不是一个集群问题,它无法扩展问题,不是吗?群集进行内部扩展,您可以将其限制为一个用于调度服务....但是当您将跨多个VM(多个Heroku dyno,多个docker容器等)进行扩展时,这仍将分崩离析...这将是定时节点计划作业的来源?