workflow-es icon indicating copy to clipboard operation
workflow-es copied to clipboard

Limit retries based on maxRetryCount

Open vimalraj-a opened this issue 7 years ago • 5 comments

How do set max retry count? I have a requirement that I need to do 3 reties before concluding the step as error.

vimalraj-a avatar Jan 24 '19 09:01 vimalraj-a

That is a feature that still needs to be implemented. My thinking is that you should be able to specify a retry count and what action happens after that (terminate or suspend)?

danielgerlag avatar Jan 25 '19 04:01 danielgerlag

You can also access the retry count from within your step

context.pointer.retryCount

danielgerlag avatar Jan 25 '19 04:01 danielgerlag

Even I get the retryCount in step. How do I change error handling strategy of workflow from run method?

I can't force termination of workflow from step body.

vimalraj-a avatar Jan 25 '19 19:01 vimalraj-a

yes, this feature is lacking at the moment

danielgerlag avatar Jan 29 '19 04:01 danielgerlag

@vimalraj-a

Even I get the retryCount in step. How do I change error handling strategy of workflow from run method?

You can override the strategy by doing

context.step.errorBehavior = WorkflowErrorHandling.Terminate;

Your step could then look like

class FailingStep extends StepBody {
    private retryLimit = 2;
    async run(context: StepExecutionContext): Promise<ExecutionResult> {
        if (context.pointer.retryCount >= this.retryLimit) {
            console.log('retry limit reached');
            context.step.errorBehavior = WorkflowErrorHandling.Terminate;  // here we override the error handling strategy
            throw new Error('This step has failed too many times : Terminating');
        }
        // try to do something that fails
        throw new Error('This step failed');
    }
}

Duwab avatar May 26 '20 15:05 Duwab