Custom Activity ( V. ) Stop an activity
No matter whether you use the words "stop", "give up", "stop", or "interrupt", you cannot directly express what I mean here! This is the biggest obstacle to encapsulating business logic to custom activities so far, because in terms of custom audit activities, each activity in the workflow designed by the user may be executed multiple times. For example, if you need multiple people to participate in the review at the same level, if the condition is not met, the operation will be stopped. Then, wait for the next user to enter the basic data for calculation and re-execute the logic, until the activity is completed and transitioned to the next activity. It should be noted that the logic of the custom activity here includes the reading of basic data, the judgment of the condition and whether to execute it, the waiting in situ or the rollback process, instead of using a lotWFPreset activities are supported. All functions are encapsulated in one activity. In addition, rollback is not described here. For details about rollback, refer to the subsequentArticle.
InWFOfSDKThere is a key term"Persistence
PointIt determines the next LoadingWFThe starting point of the instance. I will use this word to explain some problems. Let's take a look at its impact in our "interrupted" workflow!
We have tried multiple methods to "interrupt"WFInstance running, such:
- Kill a thread or process. This method can makeWFThe logic of the interrupted activity that the instance is reloaded and re-executed. However, this method is not available in practical applications and has many negative effects.
-
- CallWorkflowinstance. Abort. The result of this method is uncertain. It will be described below.
- CallWorkflowinstance. Terminate, This method does not work, WillWFThe instance is cleared from the database !!!
- Call Workflowinstance. Unload This method does not work either. This method will be persistent first, and then "Abort" WF Instance running. Because" Persistence point "Is located behind the intermediate logic of the activity-the request" interrupted ", resulting in WF The instance cannot be loaded and run !!!
- An exception occurs in the activity execution logic. We have never succeeded in this method, the final result will also be WF the instance is cleared from the database !!!
the breakthrough point is abort but we almost gave up on this. The specific process is not clear, it seems that you cannot directly call WF instance abort method, it can only be handled by the engine. How can I control activities in a subtle way to the engine? My colleague Xu daosong took some time :). The solution is to return executing Status, which triggers the onidel event, and then in the engine's onidel calling in event processing WF instance abort method. However, this is not the end of the problem.
We useSqlworkflowpersistenceserviceTo carry out our persistence work. In its constructor, there isUnloadonidleThis parameter makes us a lot of trouble. If this parameter is trueOnidelCall in eventWFInstanceUnloadMethod to form a dirty"Persistence point". Therefore, you must set this parameterFalse.
The problem of repeated execution of the same activity has been solved. So far, the topic of the custom activity will end. The following describes the specific design of the custom audit activity, to be continued!