cancel
Showing results for 
Search instead for 
Did you mean: 

Boundary event after Java Service Task retry failure?

eputtone
Champ in-the-making
Champ in-the-making
Hello,

I have a process that contains Java Service Tasks with activity:async=true. I have successfully implemented an own Command / CommandFactory, which replaces the default retrying behavior (DecrementJobRetriesCmd / DefaultFailedJobCommandFactory) for async continuations.

When the retries left count reaches zero, Activiti stops the job. I could probably trigger it active again, but it would only continue retrying the same service task. Instead, I would like to exit the service task through e.g. an error boundary event.

Is there a way detect (in JavaDelegate perhaps) the last retry and raise BpmnError? Or some other way to continue automatically before Activiti stops the job because of too much retrying?

Thanks!
- Esa

2 REPLIES 2

eputtone
Champ in-the-making
Champ in-the-making
Found out that one way is to modify ServiceTaskDelegateExpressionActivityBehavior exception handling by following an optional transition when retrying is about to end. Not very clean, but seems to work.

<java>
public class ServiceTaskDelegateExpressionActivityBehavior extends TaskActivityBehavior {

  public void execute(ActivityExecution execution) throws Exception {
    try {

    } catch (Exception exc) {
      Throwable cause = exc;
      BpmnError error = null;
      while (cause != null) {
        if (cause instanceof BpmnError) {
          error = (BpmnError) cause;
          break;
        }       
        cause = cause.getCause();
      }
      if (error != null) {
        ErrorPropagation.propagateError(error, execution);
      } else {
        if (Context.getJobExecutorContext().getCurrentJob().getRetries() > 1) { 
          throw exc;
        } else {
          PvmTransition transition = execution.getActivity().findOutgoingTransition("retrying-finished");
          if (transition != null) {
            execution.take(transition);
          } else {
            throw exc;
          }
        }
      }
    }
  }
}
</java>

mystarrocks
Champ on-the-rise
Champ on-the-rise

This is exactly my use case as well. Years later, is there a solution now that does not involve overriding ServiceTaskDelegateExpressionActivityBehavior's execute method to detect when we are about to retry for the last time?