Suspend a Process Instance

I am struggling to automate suspension in a BPMN model. For insolated testing, I have a simple BPMN model with a start, end, and two groovy script tasks. The first task writes a printline, “Script 1”. The second task calls sleep 45000 then prints “Sleep Complete.” Both tasks are async and exclusive. I cannot suspend the sleep process without receiving an error. Scouring the documentation and forum posts, I have tried:

  1. Calling PUT flowable-rest/service/runtime/process-instances/{processInstanceId}
  2. Calling the REST service process definition.
  3. Creating a second workflow containing a Service Task that calls a Java class implementing ActivityBehavior. In the execute method, get the Context RuntimeService and suspend process instance by id.
  4. Creating a subprocess in the workflow calling the Serivce Task above.

Each of these attempted solutions resulted in a FlowableOptimisticLockingException or a Postgresql deadlock error. Is there another way to implement process instance suspension on a running workflow? An explicit example would be helpful, if possible.

The problem is most likely that suspending an instance that is currently executing (the second groovy task) will lead to concurrent updates to the same instance. The engine correctly detects this and rolls one back with an optimistic locking exception.

As Flowable typically runs on multiple nodes at the same time, there’s no direct way to check if an instance is still being executed concurrently.

One option could be to wrap the suspension in an async job (with custom JobHandler) that is exclusive for the same process instance. But that’s quite a bit of low-level work.