Skip to main content
Level 2
Apr 16, 2021 2:18 PM UTC
Solved

Stop retrying Workflow using java

Hi,

I have a custom workflow which I don't want to be retried if fails.

if (schemaErrors.size() > 0) {

                // session.terminateWorkflow(item.getWorkflow());

                String message = LOG.log(Messages.EXCEPTION_RUNNING_UPGRADE_WORKFLOW);

                throw new WorkflowException(message);

}

Is there a way to stop retrying once I throw a workflow exception? I have tried with terminateWorkflow but it doesn't seem to work.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Ravi_Pampana
Ravi_PampanaAccepted solution
Community Advisor
Apr 16, 2021 3:38 PM UTC

Hi,

 

If you throw WorkflowException then WF engine will retry the workflow later based on the AEM workflow Engine configuration. If you remove throwing the exception then retry should not occur.

 

throw new WorkflowException("Unable to complete processing the Workflow Process step", e);

Ravi Pampana

2 replies

Asutosh_Jena_
Community Advisor
Community Advisor
Apr 16, 2021 2:49 PM UTC

Hi @infinityskyline 

 

Within the execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) you can write the below step which will terminate the workflow.

 

Workflow workflow = workflowSession.getWorkflow(workItem.getWorkflow().getId());
workflowSession.terminateWorkflow(workflow);

 

Thanks! 

Translate
Ravi_Pampana
Community Advisor
Ravi_PampanaCommunity AdvisorAccepted solution
Community Advisor
Apr 16, 2021 3:38 PM UTC

Hi,

 

If you throw WorkflowException then WF engine will retry the workflow later based on the AEM workflow Engine configuration. If you remove throwing the exception then retry should not occur.

 

throw new WorkflowException("Unable to complete processing the Workflow Process step", e);

Translate
Ravi Pampana