Windows 工作流 - 有没有一种方法可以保证只运行一个工作流?
该工作流正在作为 wcf 服务发布,我需要保证工作流按顺序执行。有没有办法(在代码或配置中)来保证运行时不会同时启动两个工作流程?
The workflow is being published as a wcf service, and I need to guarantee that workflows execute sequentially. Is there a way--in code or in the config--to guarantee the runtime doesn't launch two workflows concurrently?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
无法配置运行时来限制正在进行的工作流数量。
但请考虑工作流程本身有责任控制流程。因此,工作流本身应该具有确定其自身的另一个实例当前是否正在进行的方法。
我会考虑创建一个活动,该活动将尝试以事务方式更新数据库记录,以达到此工作流程的实例正在进行中的效果。如果发现另一个正在进行中,它可以采取适当的行动。它可能会失败,也可能会使用 EventActivity 自行排队,以便在上一个工作流程完成时收到警报。
There is no way to configure the runtime to limit the number of workflows in progress.
Consider though that its the responsibility of the workflow itself to control flow. Hence the workflow itself should have means to determine if another instance of itself is currently in progress.
I would consider creating an Activity that would transactionally attempt to update a DB record to the effect that an instance of this workflow is in progress. If it finds that another is currently in progress it could take the appropriate action. It could fail or it could queue itself using an EventActivity to be alerted when the previous workflow has completed.
您可能需要在工作流程启动时检查另一个正在运行的实例。
如果发现,取消它。
You probably will need to check at workflow start for another running instance.
If found, cancel it.
我不同意这需要在 WorkflowRuntime 级别处理。我喜欢自定义 Activity 的想法,类似于 MutexActivity,它是具有数据库后端的 CompositeActivity。第一次执行将记录到拥有互斥锁的数据库。后续调用会将其工作流 ID 排队,然后进入空闲状态。当 MutexActivity 完成时,它将释放 Mutex,加载队列中的下一个工作流并调用所包含的子活动。
I don't agree that this needs to be handled at the WorkflowRuntime level. I like the idea of a custom Activity, sort of a MutexActivity that would be a CompositeActivity that has a DB backend. The first execution would log to the database it has a hold of the mutex. Subsequent calls would queue up their workflow IDs and then go idle. When the MutexActivity completes, it would release the Mutex, load up the next workflow in the queue and invoke the contained child activities.