简体   繁体   English

工作流持久性和书签作为工作流故障转移

[英]Workflow persistence and bookmarks as a workflow failover

I have set of custom activities, which are used in complex workflows. 我有一组自定义活动,用于复杂的工作流程。

I would like to make them (custom activities) persistable without having workflow in an idle state. 我想让它们(自定义活动)保持不变,而不需要工作流处于空闲状态。 It should be kind of failover system, so whenever something goes wrong during execution of a workflow it can be either: 它应该是一种故障转移系统,因此在执行工作流时出现问题时,它可以是:

  • paused by a user (in anytime) and resumed later from the bookmark/point it was paused (for example user has noticed that an external system is down and he wants to pause the workflow for time being). 用户暂停(在任何时间)并稍后从书签/点恢复它暂停(例如,用户已经注意到外部系统已关闭并且他希望暂时停止工作流程)。
  • in case of an unhandled exception we can restart execution from last bookmark/point in time 如果是未处理的异常,我们可以从上一个书签/时间点重新开始执行
  • stop of WorkflowApplication host can happen anytime and we can restart execution from last bookmark/point in time WorkflowApp宿主的停止可以随时发生,我们可以从上一个书签/时间点重新开始执行

I've worked for few days with workflow persistance, but I am not sure if I can achieve my goal with it. 我已经工作了几天工作流程持久性,但我不确定我是否可以实现我的目标。 Why? 为什么?

  • I could use blocking bookmarks in each custom activity, but blocking a workflow and restarting it just for purpose of having it persisted doesn't look promising. 我可以在每个自定义活动中使用阻止书签,但阻止工作流并重新启动它只是为了让它保持不变看起来并不乐观。
  • I could use notblocking bookmarks, but I was not able to see them in database and resume from it. 我可以使用notblocking书签,但我无法在数据库中看到它们并从中恢复。

Can you please advice me, it workflow bookmarks are the way to go here? 你可以请教我,它的工作流程书签是去哪里的?

I see some light in notblocking bookmarks, but I cannot persist them and resume later on. 我看到一些没有阻止书签的亮点,但我不能坚持下去并稍后恢复。 Can you please give me some hints how to persist a nonblocking bookmark for later resume? 你能不能给我一些提示,告诉我如何为以后的简历保留一个非阻塞书签?

Edit: 编辑:

In wf3 there was an attribute PersistOnClose which would be enough for my requirement. 在wf3中有一个属性PersistOnClose ,这足以满足我的要求。 in wf4 it was replaced with Persist activity, which could also be useful, however I do not want to have extra activities in my already complex workflows. 在wf4中,它被Persist活动取代,这也很有用,但是我不希望在我已经很复杂的工作流程中有额外的活动。

Ideally, it would be great to be able to execute context.RequestPersist(callback) from NativeActivityContext , however this method is internal (and everything what is inside it is not visible outside of original assembly. 理想情况下,能够从NativeActivityContext执行context.RequestPersist(callback)会很棒,但是这个方法是内部的(并且其中的所有内容在原始程序集之外是不可见的。

Here is what I came with: 这是我的意思:

  • Non-blocking bookmarks are not an option. 非阻止书签不是一种选择。 Although a non-blocking bookmark does not prevent the creating activity from completing but it also does not cause the workflow instance to become idle - which means it will not be persisted. 虽然非阻塞书签不会阻止创建活动完成,但它也不会导致工作流实例变为空闲 - 这意味着它不会被持久化。 Non-blocking bookmarks are discarded once the activity (which created it) completes. 一旦活动(创建它)完成,就会丢弃非阻塞书签。 This bookmark can be resumed only if creating activity has not completed. 仅当创建活动尚未完成时,才能恢复此书签。
  • Using PersistOnCloseAttribute is not an option, because I'm using WF4 and this attribute is only .NET 3.x WF. 使用PersistOnCloseAttribute不是一个选项,因为我使用的是WF4,这个属性只有.NET 3.x WF。
  • Blocking bookmarks cannot be used, because they block execution of a workflow, which is not desired. 无法使用阻止书签,因为它们阻止了工作流的执行,这是不希望的。

The solution is to use Persist activity in each custom made activity (has to extend NativeActivity which can schedule child activities): 解决方案是在每个自定义活动中使用Persist活动(必须扩展可以安排子活动的NativeActivity ):

//class field
Activity childActivity = new Persist();

In order to make it work, it has to be added to metadata as ImplmentationChild: 为了使其工作,必须将其作为ImplmentationChild添加到元数据中:

protected override void CacheMetadata(NativeActivityMetadata metadata)
{
     base.CacheMetadata(metadata);
     metadata.AddImplementationChild(this.childActivity);
}

The last thing is to schedule child activity from Execute method (doesn't matter where, persistence will happen only after calling activity is completed*). 最后一件事是从Execute方法安排子活动(无论何处,只有在调用活动完成后才会发生持久性*)。

protected override void Execute(NativeActivityContext context)
{
    //...
    context.ScheduleActivity((Activity)this.childActivity);
}

In order keep the workflow persisted after unhandled exception, this piece of code have to be added to WorkflowApplication: 为了在未处理的异常之后保持工作流程保持不变,必须将这段代码添加到WorkflowApplication:

 application.OnUnhandledException = delegate(WorkflowApplicationUnhandledExceptionEventArgs e)
 {
      return UnhandledExceptionAction.Abort;
 };

*return from the Execute method doesn't necessarily mean that the activity is "completed" - ie there are blocking bookmarks inside activity (see drawbacks below). *从Execute方法返回并不一定意味着活动已“完成” - 即活动内部存在阻止书签(请参阅下面的缺点)。

There are few drawbacks of this solution: 这个解决方案有一些缺点:

  • Solution keeps only one state of the workflow (the last state). 解决方案仅保留工作流的一个状态(最后一个状态)。
  • Persistence can happen only when activity has completed. 持久性只有在活动完成后才会发生。 Which means that persist/resume cannot be done from the middle of an activity. 这意味着无法从活动中间完成持久/恢复。
  • It does not work with parallel loops/sequences - activities from parallel loop/sequence are persisted after entire parallel thing is completed. 它不适用于并行循环/序列 - 并行循环/序列中的活动在完成整个并行操作后保持不变。 It works correctly with regular loops/sequences. 它可以正常循环/序列。
  • Blocking bookmarks have a huge influence on this solution (if they are created in creating activity or in other child activities of creating activity). 阻止书签对此解决方案有很大影响(如果它们是在创建活动或创建活动的其他子活动中创建的)。 They cause that activity is not completed, even though Execute method returned. 即使返回了Execute方法,它们也会导致活动未完成。 Eventually Persist will execute (either after completion of activity or before going into idle state). 最终Persist将执行(在完成活动之后或进入空闲状态之前)。

If i understand you question correctly then, you have below requirements. 如果我理解你的问题,那么你有以下要求。

  1. Persistence and recovery of workflow. 持久性和恢复工作流程。
  2. User can pause and resume. 用户可以暂停和恢复。
  3. In case of any exception, workflow persisted and resume from next activity. 如果出现任何异常,工作流程将保持不变并从下一个活动中恢复。

You can approach using below steps. 您可以使用以下步骤。

  1. You can use WF + WCF service to execute and host your workflow. 您可以使用WF + WCF服务来执行和托管您的工作流程。
  2. Add persistence and tracking with a data base like Sql server, if you are using oracle then can use Devart. 使用像Sql server这样的数据库添加持久性和跟踪,如果您使用的是oracle,则可以使用Devart。
  3. Configure ControlEnpont to pause and resume. 配置ControlEnpont以暂停和恢复。
  4. Use try/ Catch and persistence activity wisely to handle exception. 明智地使用try / Catch和持久性活动来处理异常。

in case of any issue and customization required discussed same.:) as I have developed workflow like similar like yours. 如果有任何问题和定制需要讨论相同。:)因为我已经开发了类似你的工作流程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM