Are activity interceptors the way to go to perform side effects when retrying more than x attempts?

Hi,

I would like to know if ActivityInboundCallsInterceptorBase is the way to go in order to execute custom logic if an activity encounters a certain error for more than x attempts.

Basically I would like to for my activities to keep retrying, so that technicians can deploy needed fixes and have the workflows progress forward, but at the same time, I would like to notify certain people if more than X attempts happened.

Thanks :slight_smile:

I am struggling with how to deal with intermittent failures.

You can access the number of attempts in ActivityInboundCallsInterceptor and perform the necessary notification.

Thanks for the reply.
I have a couple of questions regarding how to implement this.

public void init(ActivityExecutionContext context) gives me access to the attempt by first getting ActivityInfo.
However I donโ€™t have this information in public ActivityOutput execute(ActivityInput input).
From the two methods, it seems to me that Iโ€™m supposed to store locally the number of attempts of the activity and then use that value in execute.

Is this correct?

Also, could you clarify the lifecycle of the interceptor?

Finally, Iโ€™ve seen @Experimental annotation in the SDK, do you recommend using it?

Thanks a lot!

The inbound interceptor is created by WorkerInterceptor.interceptActivity method which is called per activity invocation. So you can create an instance of your interceptor per activity invocation, which means you can use the interceptor fields to pass data from one method to another.

It is also possible to use Activity.getExecutionContext in the execute method to get the context.

1 Like