具有完成任务的服务结构任务队列 [英] Service fabric task queue with completion task
问题描述
我有一份工作可以分解为一些较小的任务,每个任务最多可能需要30分钟才能完成.任务完成后,必须运行清理任务.
I have a job that can be broken down into smaller tasks, each that may take up to 30 minutes to complete. After the tasks are complete, then a cleanup task must be run.
每个任务都是CPU密集型操作,必须在单独的计算机上运行.
Each Task is a CPU intensive operation that must be run on a separate machine.
问题是我无法找到一种方法来知道所有任务何时完成.如何在Service Fabric中创建应用程序,以便在完成所有任务后可以运行其他清理任务?
The problem is that I can not find a way to know when all tasks are complete. How can I create an application in Service Fabric, such that when all tasks are complete, an additional cleanup task can be run?
此外,如何使它在任何任务失败或意外关闭时,向所有工作程序发送取消信号,然后调用清除任务?
Additionally, how can I make it such that when any of the tasks fail or unexpectedly shut down, a cancellation signal is sent to all workers, and then call the cleanup task?
推荐答案
您也可以根据需要使用ServiceFabric Actors.
You could also use ServiceFabric Actors for your requirement.
- 创建一个触发该任务的中央"JobService"(例如,托管WebApi的无状态服务)
- 创建一个"TaskActor"来处理单个任务
- 在ActorInterface中发布一个cancellishToken
- Create a central "JobService" that is triggered to do the work (e.g. a stateless service that hosts a WebApi)
- Create a "TaskActor" that will handle a single task
- Publish a cancellationToken in the ActorInterface
您可以看一下分区概念,以了解参与者如何在您的节点上分布.
You could take a look at the partition concept to see how the actors are spread across your nodes.
根据您的情况,actorId可以保持一致(例如taskActor1,taskActor2)以重复使用资源,也可以使用GUID使它们对于每个作业都是唯一的.
Depending on your scenario, the actorIds could be consistent (e.g. taskActor1, taskActor2) to reuse the resources, or you could use a guid to make them unique for every job.
这篇关于具有完成任务的服务结构任务队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!