Timeouts From Configurations

Hey Everybody!

I have a spring boot micro service that we use to run Workflows with Temporal.
Currently, our workflow hardcode the following timeouts:

private static final Duration SCHEDULE_TO_CLOSE_TIMEOUT = Duration.ofHours(24);
private static final Duration START_TO_CLOSE_TIMEOUT = Duration.ofMinutes(30);
private static final Duration HEARTBEAT_TIMEOUT = Duration.ofSeconds(60);

My goal is to find a way to inject this configuration from config file as opposed to have it hardcoded within the Workflow. I have read a few topics on this forum where it is advised agains injecting configuration within a workflow as it might create non-determinism (Integration with Spring and self registration of workflows and activities and Temporal with springboot).

That said, we found an hack to actually inject this configuration by taking advantage of the addWorkflowImplementationFactory method. However, this is discouraged even in the doc and as a solution for passing configuration it is recommended to use a LocalActivity. While this would work for common Workflow configuration, I don’t think this would work in my case as I am trying to bring in a configuration for the ActivityOption itself, which I would need before the Local Activity even starts.

Do you have any recommendation for this? Should I just stick to the hardcoded solution? Would there be any issue if we change timeouts while other workflows are running?

Hi @Claudio_Rizzo

You can create a LocalActivity with default LocalActivityOptions, use the localActivity to load the configuration, and then create another Activity stub with the configuration returned by the first localActivity.

Timeouts and other attributes are recorded in the event history, once an activity is scheduled you can not change them. If you change the hardcoded timeouts and redeploy the worker, the activities scheduled after redeploy will be created with the new timeouts. Loading the configuration using a localActivity will prevent this from happening since the values returned by localActivities (and activities) are recorded in the event history and won’t be affected by any subsequent change.

You can also set them through WorkflowImplementationOptions.setActivityOptions.

Thank you @antonio.perez ! I implemented a solution based on your suggestions which seems to work fine!

@maxim, thank you for the advice there! I will try that out!