How to set Retry option dynamically

Hi,

I have an activity interface that has only one method called run.

@ActivityInterface
public interface RunnableTask {
    void run(MyObj input);
}

I will be calling this activity method by iterating a loop, each time it will be served to a different input. For each method call, I want to configure different retry configurations?

Is that possible?

Yes, by creating a new activity stub for each configuration.

 RunnableTask runnableTask =
            Workflow.newActivityStub(
                    RunnableTask.class,
                    ActivityOptions.newBuilder()
                            .setRetryOptions(
                                    RetryOptions.newBuilder()
                                            .setMaximumAttempts(2)
                                            .build()
                            )
                            .setStartToCloseTimeout(Duration.ofSeconds(40)).build());

Q1). Like I did above I have to update my runnableTask with newer retry configuration each time before invoking the run method?
Is this recommended?

Q2). If I have multiple activity methods in my activity interface, can I provide different retry configuration for each method?

Q1: Yes, it is recommended if you need per request activity options.

Q2: Yes you can since the last release. Use Workflow.newActivityStub(, options, perActivityMethodOptions).

1 Like