Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

Terminating (forceful) a running workflow instance


Level 2

I'm trying to terminate certain workflows based upon threshold value of custom batch processing limit. But when I'm trying to terminate by using WF api, I could notice a strange behavior in the below snippet.

1:   WorkflowSession wfs = workflowService.getWorkflowSession(rr.adaptTo(Session.class));

2:   try {

3:      log.debug(" Is Workflow active?? "+wf.isActive());

4:      wfs.terminateWorkflow(wf);

5:   } catch (Exception e) {

6:   e.printStackTrace();


Just before calling the terminateWorkflow method, if I check the wf state by various ways e.g.

i)   By using isActive() method

ii)  By retrieving the valuemap of the particular workflow id from the var/workflow/instances/server0..... path and checking the jcr property 'state'.

iii) By using WorkflowStatus interface

But even if all above steps show a workflow is RUNNING or active, yet when flow reaches line 4 immediately, exception is throws as:

java.lang.IllegalStateException: Workflow is already finished.

Has anyone faced any similar kind of scenario?

N.B.  - The execution is carried on single thread operation(of ActionManager) unlike multi-threaded execution.

0 Replies