Customize the behavior of retry dynamically upon activity failure

Suppose in the workflow there is an activity “A” that can fail due to various factors in the external system. The default retry behavior in temporal is to re-run A in configurable intervals. What if I want to decide what to do upon A run into failure dynamically?

For example, if activity A fails due to reason X, I want to retry A at a later time. If A fails due to reason Y, I want to start a new activity B next. If A fails due to reason Z, I want to do something else etc.

I guess the most straightforward approach to implement this dynamic retry is to put some if/else if code in the workflow based on the result of A’s previous run. This just feels too cumbersome. Is there any better way to do it in temporal? Does temporal offer any utility for this?

Thanks

Correct. If you want customized retry logic, that code has to live somewhere, what better place than the workflow. It should not be seen as too cumbersome if you need to do custom logic to have to write that logic.