Service fabric task queue with completion task

♀尐吖头ヾ 提交于 2019-12-11 07:42:16

问题


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.

Each Task is a CPU intensive operation that must be run on a separate machine.

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?


回答1:


You could also use ServiceFabric Actors for your requirement.

  • 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
  • In your "JobService", give every task a unique id and use this as the "ActorId"
  • In Your "JobService", wait for the actors to complete the tasks and trigger the cleanup once all are complete. You can also cancel the other actors if one of them throws an exception.

You could take a look at the partition concept to see how the actors are spread across your nodes.

https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-actors-platform#service-fabric-partition-concepts-for-actors

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.




回答2:


Consider using an event driven (or pub/sub) approach for this.

The 'start-task' can notify how many sub tasks to expect. Every completed task can fire an event. The cleanup task can wait for the start event, and all completion events. After cleanup it can notify listeners itself, if needed.

In a similar way, events can contain info about progress, failures and cancellation.



来源:https://stackoverflow.com/questions/46386243/service-fabric-task-queue-with-completion-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!