【发布时间】:2016-06-16 17:26:40
【问题描述】:
给定一个提交给 parentWorker 的有效负载:
- 我将工作分配给 otherWorkers,并将 parentWorker 的 taskId 作为附加属性添加到负载中
- 其他每个工人都完成了他们负责的工作
我想知道是否有 5 个或 10 个或 20 个 otherWorkers 排队/开始,那么他们什么时候完成?因为当所有这些都完成后,我想开始我的工作流程的下一部分:nextWorker!
所以理想的管道是:parentWorker > X # of otherWorkers > everyone done? > nextWorker
我怎样才能做到这一点?
请不要使用基于轮询的解决方案来回答。我不是在找那个。
我想过使用缓存:
- parentWorker 将设置将创建的 otherWorkers 的总数,例如:
cachekey_<parertTaskId>_workersCreated: 10 - 那么 otherWorkers 将在完成后自动将 # 递减 -1,最终计数将达到零:
cachekey_<parertTaskId>_workersCreated: 0但应该由谁来处理该计数?
a) 如果想法是让 otherWorkers 递减它,那么检查该值并查看它是否为零并启动 nextWorker ...在以下情况下存在缺陷:
cachekey_<parertTaskId>_workersCreated: 2
otherWorker9 sends -1
otherWorker10 sends -1
otherWorker9 checks and otherWorker10 checks
both get back 0 and both will kick off nextWorker! We only wanted one instance.
b) 其他坏主意:
cachekey_<parertTaskId>_workersCreated: 2
otherWorker9 checks and otherWorker10 checks
neither one kicks off nextWorker because value!==1
otherWorker9 sends -1
otherWorker10 sends -1
its over and noone is left to act on cachekey_<parertTaskId>_workersCreated: 0
【问题讨论】:
标签: distributed iron.io ironworker