What is the way t suspend a Job?

Hi Team,

I have a small question. Once we deploy the bpmn model, we can start the process and then the processinstance is created under processdenition. On invoking the same process again, one more processinstance gets created under the same processdefinition. I found a way to suspend/resume the processinstance.

image

Lets say i want to suspend/resume by selecting Task1 / Task1_2 what is the way to do it?

Hey @Vamsi,

welcome to the forum!

I am not entirely sure I fully understood what you want to achieve here.
It looks to me that you want to do two things here:

  1. Query for a specific process instance.
  2. Suspend/Resume the process instance you searched for.

Searching for a specific instance depends on a lot of things. You can query for all process instances that are currently at Task1 by a call to the REST API like

<engine-url>/engine-rest/process-instance?activityIdIn=Task1

or via Java API like

List<ProcessInstance> instances = getRuntimeService().createProcessInstanceQuery().activityIdIn("Task1").list();

You might receive multiple instances to that query and the result can be empty as well of course.
Furthermore, there are a lot more parameters to query by, feel free to inspect them.

Once you identified the instance you want to handle, use the REST API to suspend/resume it.
You can also make use of one of the other suspend/activate endpoints you can find here.

You can do this via Java API as well of course by using one of the following

getRuntimeService().suspendProcessInstanceById(processInstance.getId());
getRuntimeService().suspendProcessInstanceByProcessDefinitionId(processDefinitionId);
getRuntimeService().suspendProcessInstanceByProcessDefinitionKey(processDefinitionKey);

Hope that helps you.

Cheers,
Tobias

Hi Tobias,

Thanks for the response. A small question here.

When ever a task in the processinstance is running and when i suspend the process instance, the running task is getting completed in the back ground but the transaction getting rolled back with optimisticlock exception , which means as per camunda this task is not completed. After activate, this rolled back task is re-running again.

  1. The first requirement is that, Once we suspend, the task which is running currently should get into sleep state /pause state. Is this possible by any ways? Currently it is running in back end and the transaction is rolled back with optimistic lock exception.

  2. If the above case is not possible, Is there any way on how to overcome the optimistic lock exception , When we activate the processinstance, this task should not get re-run again.

Thanks
Vamsi