Windows 工作流 - PersistableIdle
在我们公司,我们有一个业务流程需要:
- 从 X 获取数据
- 等待用户 Y 进行研究
- 根据步骤 2 的数据从 Z 获取数据
在研究这一点时,似乎有一些选项可以在工作流程中实现这一点。
- 在步骤 1(工作流活动)和步骤 3(工作流活动)之间添加延迟活动。然后在 PersistableIdle 事件期间卸载工作流。当用户完成步骤 2 后,从数据库重新加载工作流程。
- 与 #1 相同,只是使用书签而不是延迟活动。
是否有更好的方法(1、2 或其他选项)?
我们所有其他活动都是 AsyncCodeActivities,因此我相当确定它们不会触发 PersistableIdle 事件(因为它们位于非持久区域),但我想确保工作流程在其他情况下不会意外卸载。这里有什么风险吗?是否有办法创建一个强制工作流程卸载的活动?
In our company we have a business process that needs to:
- Get data from X
- Wait for user Y to do research
- Get data from Z based on step 2 data
In researching this, it seems like there are a few options to implement this in workflow.
- Add a delay activity between Step 1 (workflow activity) and Step 3 (workflow activity). Then during the PersistableIdle event, unload the worklow. When the user is done with step 2, re-load workflow from database.
- Same as #1 except use a bookmark instead of a delay activity.
Is there a better approch (1, 2 or another option)?
All of our other activities are AsyncCodeActivities, so I'm fairly sure they will not fire the PersistableIdle event (since they are in a no-persist zone), but I want to make sure the workflow is not accidentally unloaded in other cases. Is there any risk here? Is there anyway to create an activity that forces the workflow to unload?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
乍一看,#2 听起来很有必要。使用书签(或某种书签活动,如接收)的原因是它们可以随时恢复。这允许用户 Y 的研究结束,并且工作流可以随时恢复执行(而不是被阻止直到延迟到期)。
反对意见是,#1 也可能是必要的,您可能希望设置一个触发工作流程操作的时间限制(触发提醒、例外、取消等)。
如何决定?我认为答案通常是#3:两者都
使用 Pick Activity 是同时实现这两点的好方法。在一个 PickBranch 触发器中使用 Bookmarking 活动,并在另一个 PickBranch 触发器中使用 Delay 活动,您可以编写一个工作流程,该工作流程将“处理先发生的情况 - 用户 Y 或超时”。
您提出的第二个问题是“当我不希望卸载工作流程时,如何停止卸载工作流程 - 意外工作流程卸载是否存在风险”?
嗯,这要看情况。如果您使用 WorkflowServiceHost,卸载工作流不会感觉有很大风险,因为 WorfklowServiceHost 足够智能,可以在需要执行更多工作(处理传入消息或从延迟中恢复)时重新加载工作流。
如果您没有使用 WorkflowServiceHost,您可能正在编写主机,您可以通过一些工作实现相同的效果,或者您可以阻止卸载发生 - 当您编写主机时,您可以通过事件控制卸载策略关于 WorkflowApplication
其他杂点:
- 异步代码活动确实会阻止您的工作流程在执行异步工作时持续存在。我认为它们不应该被故意用作反持久性机制 - 如果您想要其中一个,请查看 NoPersistZone 活动。
- 没有“卸载”活动,但有“保留”活动。工作流可以说他们想要保存进度,但只有主机才能对何时进行卸载做出最终决定。
At first glance, #2 sounds like necessary. The reason to use bookmarks (or bookmarking activity of some kind, like Receive) is that they can be resumed any time. This allows for user Y's research to end and the workflow to resume execution at any time (instead of being blocked until a Delay expires).
The counterargument, that #1 may be necessary too, is that you may wish to set a time limit which triggers workflow actions (reminders being fired off, exceptions, cancellations, etc).
How to decide? I think the answer is usually #3: Both
Using Pick Activity is a great way to do both. Using Bookmarking activity in one PickBranch trigger, and Delay activity in the other PickBranch trigger, you can compose a workflow which will 'handle whichever happens first - user Y, or timeout'.
A secondary question you raise is 'How do I stop a Workflow being unloaded when I don't want it to be - is surprise workflow unloading a risk'?
Well, that depends. If you are using WorkflowServiceHost, having your workflow unloaded doesn't feel like a big risk, because the WorfklowServiceHost is smart enough to reload your workflow when it needs to do more work (handle an incoming message, or resume from delay).
If you are not using WorkflowServiceHost, you are probably writing your host, you can either achieve the same effect with some work, or you can just prevent unloading from happening ever - when you write the host, you control the unload policy, via the events on WorkflowApplication
Other miscellaneous points:
-Asynchronous Code Activities do indeed prevent your workflow from persisting while they are doing asynchronous work. I don't think they should be deliberately used as an anti-persistance mechanism though - if you want one of those, check out NoPersistZone activity.
-There is no 'Unload' activity, but there is a 'Persist' activity. Workflows can say they want to save progress, but only the host gets to make the finally decision on when unloading happens.