How to access retry Time Cycle count?

I have a service task which checks if the flow can continue if e.g. a file exists. If it doesnt exists it will retry up to 3 times with some wait time inbetween. The last time it fails is it possible to get e.g. the retry count and say if it’s 0 then redirect it to another path rather than the error.

@henning just a quick idea that came to mind for this… Thoughts on using a Sequential Multi-instance service task: The Multiinstance generates 3 tasks, and you set the Multi-instance completion condition to validate to true when the file is found, otherwise the 3 tasks will execute.

something like:

@StephenOTT I like that idea, though I forgot to write that there should be a time delay before trying again e.g. wait 1 minute. I have edited my first post to reflect this. Is this revised problem still solvable with Sequential Multi-instance, cause I do not know how to delay the execution. I wouldnt mind if the first execution was delayed aswell.

Something like this?
Note: i added the script task for visual purposes only. Likely you can just add the script that updates the process variable with your completion condition into a listener or the script/delegate that runs for your service task.

Thank you for your effort. The reason I wanted to use retry Time Cycle was because we initially had a task, a timer and a gateway and I thought maybe there is a cleaner way to retry an activity x times with a delay inbetween. By adding the gate and the timer we are now back at the same complexity.

@henning why does adding th gateway and timer create “too much complexity” for you?

My problem can be solved like this, and your suggestion. And it’s something I do fairly often. Im looking for a more clean solution.

The second image is what im hoping to achieve.
I can almost achieve this with retry time cycle. It’s just that the last failure I need to direct the flow to a meaningful direction. Which would be possible if I can check a retry counter or something and say
if ( retryCounter != 0) {
DoAnotherRetry()
} else{
NoMoreTriesTakeAnotherPath()
}


@henning I was wondering what approach have worked for you best as i’m having the same scenario
(Interval check state on a remote app)

thanks.

@Asaf_Shakarzy see the link i posted in the Interval Check State on remote app link.

@Asaf_Shakarzy
I read your thread. In the end I had to modell it like this.
It’s similar to your loop. Im no fan of counters because I dont like the flow to change for no apparent reason so I circumvent that by using a timer on a subprocess.

@StephenOTT
I checked you pattern feedback time, it is interesting and make the workflow look very clean.

Camunda has its own retry engine. If the task is async (before async continuation) when occur an error the camunda will retry automatically. To access the retry count of the job, just use a code like this inside your delegate:

ManagementService managementService = delegateExecution.getProcessEngineServices().getManagementService();

    Job currentJob = managementService.createJobQuery()
            .processInstanceId(delegateExecution.getProcessInstanceId())
            .activityId(delegateExecution.getProcessInstance().getCurrentActivityId())
            .list()
            .get(0);

    Integer jobNumberOfRetriesLeft = currentJob.getRetries();