Windows 工作流 - 有没有一种方法可以保证只运行一个工作流?

发布于 2024-08-11 06:23:42 字数 72 浏览 5 评论 0原文

该工作流正在作为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蓝咒 2024-08-18 06:23:42

无法配置运行时来限制正在进行的工作流数量。

但请考虑工作流程本身有责任控制流程。因此,工作流本身应该具有确定其自身的另一个实例当前是否正在进行的方法。

我会考虑创建一个活动,该活动将尝试以事务方式更新数据库记录,以达到此工作流程的实例正在进行中的效果。如果发现另一个正在进行中,它可以采取适当的行动。它可能会失败,也可能会使用 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.

不离久伴 2024-08-18 06:23:42

您可能需要在工作流程启动时检查另一个正在运行的实例。
如果发现,取消它。

You probably will need to check at workflow start for another running instance.
If found, cancel it.

我要还你自由 2024-08-18 06:23:42

我不同意这需要在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文