Execute some code when activity retries are exhausted

Hello,

I have a temporal workflow which runs 5 activities. Each activity has different retry options and I want to run some code (which includes terminating workflow, calling a different activity) when activity retries are exhausted.

How can I achieve this ?

When an activity retries are exhausted, ActivityFailure exception is thrown to the workflow code. So your code can catch this exception and perform any necessary logic.

Thanks @maxim. Also are there any best practices of terminating a typed workflow ? Can you share some examples.

lso are there any best practices of terminating a typed workflow ? Can you share some examples.

What are you trying to achieve? Do you want to “kill -9” your workflows without any chance of orderly cleanup? Or you want to workflow to complete upon an external event?

@maxim I want to orderly terminate and cleanup the workflow when one of the activity fails after retries.

Then you just catch the exception from the activity invocation, perform cleanup in the catch block and return the workflow function.