cancel
Showing results for 
Search instead for 
Did you mean: 

Suspend and resume processinstance based on runtime conditions

rajivmoghe
Champ in-the-making
Champ in-the-making
In my process, I need to make a call to an external service. I know that this service requires 4 (non-null) values to be passed to it, let's say A, B, C, D. It is possible that these 4 values may be already available as (non-null) process variables. On the other hand, sometimes, some of these may be null.

To make things easier for the business user I plan to use the Single Service Task approach mentioned in the article at http://long-running.net/blog/2015/should-asynchronous-service-invocations-be-visible-in-a-bpmn-diagr... and the Req/Acl/Callback pattern.

This works great with the assumption A, B, C, D are present, while using a class that extends AbstractBpmnActivityBehavior, but I need the following additional functionality:
  1. If either of the parameters A, B, C, D are null, pause the processinstance, and create a task for the user that will ask for the null params.
  2. Once the params are provided in the task, the processinstance resumes its execution with all values, makes a service call, and waits for the callback to be called.

  3. Question: can this even be done? If yes, any pointers please…
3 REPLIES 3

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

If either of the parameters A, B, C, D are null, pause the processinstance, and create a task for the user that will ask for the null params.
Yes, use exclusive gateway with conditional flow.

Once the params are provided in the task, the processinstance resumes its execution with all values, makes a service call, and waits for the callback to be called.
Put this logic after the conditional flow and user task.

Regards
Martin

rajivmoghe
Champ in-the-making
Champ in-the-making
Hi Martin,

I'm using that approach already, but it entails 2 extra elements (X-GW, HT) in the flow, and 'leaks the abstraction' to the business user.

I was looking to make this a sort of 'smart activity' (read: one single box for the b.u.) , that 'knows' whether it can perform the service, and if not, wait till all the data is available to try again.

Basically, once the execution enters an activity, if it can successfully perform the service call, does it, else suspends self, till it receives a signal with the 'missing data', and then performs the service call.

The pseudocode would be somewhat like below:
[java]
    public void execute(){
     boolean allDataPresent = checkAllData();
     if(allDataPresent){
      call service;
     }
     else {
      create task to getAllData;
     }
    }
   
    public void signal(…){
     if(serviceCompletedSignal){
      add signalData to procVars;
      leave();
     }
     else{//allData is available signal
      add allData to procVars;
      execute();
     } 
    }
[/java]

Question is : Does this approach make sense in the process engine world?

Thanks
Rajiv

jbarrez
Star Contributor
Star Contributor
It does, you can pretty much do what you in an ActivityBehaviour. I've also used a similar approach in the past (logic + custom wait combined)