Search code examples
workflowaem

Purging workflow after couple minutes


I have a Workflow step which if meet issues throw WorkflowException with a message and stacktrace, in effect - blocks whole workflow launcher with the payload. Finally, the workflow is indefinitely in the RUNNING state and does not handle any updates for blocked payload. This situation requires admin action to manually terminate the workflow.

There is how the simple workflow looks:

@Service
@Component
@Properties({
        @Property(name = Constants.SERVICE_DESCRIPTION, value = "Workflow"),
        @Property(name = "process.label", value = "Workflow Step") })
public class WorkflowStep implements WorkflowProcess {

    @Override
    public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap)throws WorkflowException {       
        try {
            ... doing some stuff ...
        } catch (Exception e) {
            throw new WorkflowException(e.getMessage(), e);
        }
    }
}

I want to check after i.e 2 minutes if the workflow is COMPLETED if not - terminate them to unblock the payload and after upload the next asset into this path - again handle by the workflow.

Any idea how to solve it without using CRON Scheduler?


Solution

  • If you catch the exception, why don't you terminate the workflow right then instead of throwing a WorkflowException? You could log whatever you want, handle the error and then terminate...

    BR, Oliver