How to implement restart/pause/resume in Activiti
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2011 09:04 PM
Since Activiti has started to support asynchronous messages since 5.8, so I have implemented a 'retry' function for Activiti, user could start/restart a process instance from given activity, i.e. if a process instance is suspended at a activity, user could call this API to enable the process instance to restart from a given activity even though the activity has never run, here is the process logic(not 100% match with my code change):
1: get history process instance
2: get process definition
3: get all executions
4: get root execution(parent execution is null, if there are concurrent executions,IS_ACTIVE_=0,IS_CONCURRENT_=0,IS_SCOPE_=1)
5: get concurrent executions(IS_ACTIVE_=1,IS_CONCURRENT_=1,IS_SCOPE_=0), when concurrent execution runs to gateway activity, IS_ACTIVE_ will be 0
6: New ExecutionEntity for this activity
7: new MessageEntity for the newly created ExecutionEntity
8: New cancelJobsList object where to store those jobs need to be killed or cancelled.
9: check if given activity is on branch(outgoing transitions size > incoming transitions size)
10: if isActivityOnBranch = false
10.1: put all jobs into cancelJobsList
10.2: delete all executions
10.3: Newly ExecutionEntity.setConcurrent(false), setScope(true)
10.3: goto 11.3.3
11: if isActivityOnBranch = true
11.1: get all activities on the branch including the activities on head branch
11.2: check if root execution is existed
11.2: if isRootExecution is existed
11.2.1: if root execution has no children executions
11.2.1.1: delete the job entity of root execution
11.2.1.2: put the job id into cancelJobsList
11.2.1.3: root execution.setActive(false);execution.setConcurrent(false); execution.setScope(true)
11.2.1.4: goto 11.3.2
11.2.2: if root execution has children executions
11.2.2.1: get all concurrent executions except the execution whose activity is in the list in 11.1)
11.2.2.2: get none concurrent executions exception the executions in 11.2.1)
11.2.2.3: remove those executions from root executions
11.2.2.4: delete none concurrent executions
11.2.2.5: put the jobs of none concurrent executions to cancelJobsList
11.2.2.6: goto 11.3.2
11.3: if isRootExecution is not existed
11.3.1: New root execution, execution.setActive(false);execution.setConcurrent(false); execution.setScope(true);
11.3.2: Newly ExecutionEntity.setConcurrent(true);execution.setScope(false)
11.3.3: set the parent to newly root execution for the newly ExecutionEntity
11.3.4: save newly ExecutionEntity and MessageEntity
12: call job threads manager to cancel given jobs in cancelJobsList
13: return true
I am not sure if there is a plan for Activiti team to implement a feature like this, but I hope it could help those people who need this feature, I will discuss with our manager to decide whether or not share the code.
welcome any feedback.
1: get history process instance
2: get process definition
3: get all executions
4: get root execution(parent execution is null, if there are concurrent executions,IS_ACTIVE_=0,IS_CONCURRENT_=0,IS_SCOPE_=1)
5: get concurrent executions(IS_ACTIVE_=1,IS_CONCURRENT_=1,IS_SCOPE_=0), when concurrent execution runs to gateway activity, IS_ACTIVE_ will be 0
6: New ExecutionEntity for this activity
7: new MessageEntity for the newly created ExecutionEntity
8: New cancelJobsList object where to store those jobs need to be killed or cancelled.
9: check if given activity is on branch(outgoing transitions size > incoming transitions size)
10: if isActivityOnBranch = false
10.1: put all jobs into cancelJobsList
10.2: delete all executions
10.3: Newly ExecutionEntity.setConcurrent(false), setScope(true)
10.3: goto 11.3.3
11: if isActivityOnBranch = true
11.1: get all activities on the branch including the activities on head branch
11.2: check if root execution is existed
11.2: if isRootExecution is existed
11.2.1: if root execution has no children executions
11.2.1.1: delete the job entity of root execution
11.2.1.2: put the job id into cancelJobsList
11.2.1.3: root execution.setActive(false);execution.setConcurrent(false); execution.setScope(true)
11.2.1.4: goto 11.3.2
11.2.2: if root execution has children executions
11.2.2.1: get all concurrent executions except the execution whose activity is in the list in 11.1)
11.2.2.2: get none concurrent executions exception the executions in 11.2.1)
11.2.2.3: remove those executions from root executions
11.2.2.4: delete none concurrent executions
11.2.2.5: put the jobs of none concurrent executions to cancelJobsList
11.2.2.6: goto 11.3.2
11.3: if isRootExecution is not existed
11.3.1: New root execution, execution.setActive(false);execution.setConcurrent(false); execution.setScope(true);
11.3.2: Newly ExecutionEntity.setConcurrent(true);execution.setScope(false)
11.3.3: set the parent to newly root execution for the newly ExecutionEntity
11.3.4: save newly ExecutionEntity and MessageEntity
12: call job threads manager to cancel given jobs in cancelJobsList
13: return true
I am not sure if there is a plan for Activiti team to implement a feature like this, but I hope it could help those people who need this feature, I will discuss with our manager to decide whether or not share the code.
welcome any feedback.
Labels:
- Labels:
-
Archive
6 REPLIES 6

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2011 04:45 AM
Hi,
Do you mean restart functionality when a job has failed to execute 3 times?
Or do you mean it in a more broader perspective? Can you please elaborate a bit more on the use cases you want to cover?
Best regards,
Do you mean restart functionality when a job has failed to execute 3 times?
Or do you mean it in a more broader perspective? Can you please elaborate a bit more on the use cases you want to cover?
Best regards,
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2011 07:44 AM
Activiti does not use retry interceptor like jBPM, right? some Workflow engines like Shark have the restart functionality, when a process instance is suspended at an activity, user could use this functionality to restart the process from a given activity, for example:
here is a sample flow:
start -> A -> B -> C -> end
when process instance is suspended at B, user could use the 'restart' function to enable the process instance to re-run from A,
here is a sample flow:
start -> A -> B -> C -> end
when process instance is suspended at B, user could use the 'restart' function to enable the process instance to re-run from A,
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2011 07:53 AM
Besides, I reviewed the source code, It seems that Activiti does not support pause/resume process instance, I think it should be a basic functionality of Workflow engine, but it is very easy to implement in Activiti, from my point of view, here are two ways:
1: update job.exception to 'Paused', so job executor will not process those jobs marked as 'paused'
2: add new status 'suspended' for execution and job objects
anyway, it is not a big problem.
1: update job.exception to 'Paused', so job executor will not process those jobs marked as 'paused'
2: add new status 'suspended' for execution and job objects
anyway, it is not a big problem.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2012 04:12 AM
Dear lxjchengcu,
I'm very interested in retry function, are you still planning to share code?
Best Regards,
Alexander
I'm very interested in retry function, are you still planning to share code?
Best Regards,
Alexander
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2012 05:51 AM
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2012 03:59 AM
I´m also very interested in this feature.
Hope to see it in the next release.
Hope to see it in the next release.

