Suspending second execution of a Process

hi there, i know this is not regular use case but i try to model a process which processes a lot of data.

first the process “process data1” and if some data is broken it sets a process variable so the “check something” gate will pop up the usertask for repairing the corrupt data. at the same time the parallel gateway processes the data which has no errors. the happy case would be that the user repairs the broken data and after completing the user task the servicetask process data1 determines that the data is not broken anymore and passes it over to the process data2.

example process

the tricky case is that lets assume that we have already two executions of that process: one is at repair data2 and the first one is at repair data1. when repair data1 is completed the process data1 determines that everything is fine and passes the data to process data2. but process data2 now detects that something is not fine. remember the other execution of this process is already at the usertask repair data2. i dont want to start a second usertask. instead i want my process to detect it on the fly and skip the creating of the second (equal) usertask. well, actually at that point it only makes sense to me to close all unnecessary executions because the executions are at the same point/state.

  1. im not quite sure where to place this? should i place the code in the java class or should i override the method parseUserTask of BpmnParse? i usually choose expression as implementation of servicetask and provide a java class e. g. ExampleServiceDelegate

  2. how to reach that behaviour. i think ProcessInstanceModificationBuilder is the way to go? something like the following snippet but im not sure what “cancelAllForActivity” will do. does it also suspend the execution of that activity?

ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
runtimeService.createProcessInstanceModification(processInstance.getId())
.cancelAllForActivity(“repair data”)
.execute();

  1. your documentation says “Process instance modification within the same instance is not recommended! An activity which tries to modify its own process instance can cause undefined behavior, which should be avoided.” - in my case this means i should not suspend the execution which determines that there is already a usertask but the other one?

i looked up some other topics related to the ProcessInstanceModificationBuilder but didnt find any solutions for myself. im open for advices if there is a better way to go. thank you.

Hello @Sandra1337 ,

I would split the process up in 2 process definitions. By this, a bundle of valid data from the first processing step can be handled in a second process. At the same time, the faulty data from processing step 1 can be corrected, will then be processed and trigger another process for the second step. By this, you don’t have multiple tokens in one process instance at the same point, but you have multiple process instances handling different data each.

I attach a diagram to give you an idea.

Hope this helps

Jonathan

1 Like

Hello Jonathan,

thank you very much for your reply, I really appreciate it. Actually I prefer your suggestion because it seems like a very clean way of modelling a process to me. It prohibits more than one token in a process and makes it less complex. At this point I must reconsider the process with my team. :slight_smile:

1 Like

Hello @Sandra1337 ,

I am glad I could help you.

Jonathan