Does temporal support hot reload or dynamically changing workflow?

Suppose I have a workflow where I have list of activities defined. I have some number of activities and I started the workflow. Can I manipulate the workflow at runtime? If I want to add or remove some activity, is it possible? Will those changes show up in the workflow dynamically using some config file or something? Is it possible to do that? Or will I have to run the entire workflow again?

Hi @sanket47 can you give more info about your use case, would help with providing more detailed answer.

Can I manipulate the workflow at runtime?

Your workflow code has to be deterministic. You can have logic in your workflow code that can chose to call activities depending on for example results of a previous activity results, see sample here. You can also made decisions by handling activity failure and do things like compensation if you wanted. Can also make decisions based on data provided by signals sent to the workflow.

Also note that you do not have to set activity types in your workflow code, and can invoke activities by their string type using untyped approach, for example:

 ActivityStub stub =
        Workflow.newUntypedActivityStub(
            ActivityOptions.newBuilder().setStartToCloseTimeout(Duration.ofMinutes(1)).build());
    stub.execute("<your_activity_type>", String.class, args);

Java SDK also provides the DynamicActivity interface (see sample here) to implement any number of activity types dynamically. This is useful for things like integration with DSL/Config for example (see sample here).

Hope this helps.

1 Like

Hi, @tihomir, thank you for your reply. I was wondering if you manipulate the workflow without always explicitly changing it every time you run it.
I have a list of activities for a particular workflow. And I would like to have the option to chose which of them to run when I start the program.
For eg. I have a workflow with (A, B, C) activities defined. It first invokes A then B and then C (A->B->C). but now I want to change it so that it will only invoke A then C (A->C). Example is having a filter on some object. We only to apply A and C filters. Is that possible to do from outside our workflow program (Like passing in a list of activities to run mapped with workflow. (W1: (A,B,C), W2:(A,C)) something like this. How should we approach a problem like this?

If you have existing long-running executions for that workflow type and need to make wf code changes, would prob need to look at versioning.

You can pass a list of activities to be executed as workflow input, this is often used with dsl for example.

Can also make data-based decisions inside your workflow code, depending on result of A you can chose what to do next, see sample here.

Could use signals to update the invocation order but note you can only update the “future” not already executed activities.

I, too, am looking for a way to shorten development iterations with worker code. At present, I’m building containers and deploying them to a Kubernetes cluster via “skaffold dev”–this copies files that change into the cluster. My uvicorn API restarts when it detects file changes. How can we make a Temporal worker restart on file changes, too?

I’m currently looking at implementing a file watcher using inotify to kill and restart the whole worker.py process. This is based on the script here: shell - Restart process on file change in Linux - Stack Overflow

Caveat: I’m also using an ephemeral Temporal Dev Server that starts fresh when I fire up “skaffold dev”. So, there aren’t any running workflows. Also, I know this is going to break things if I mess with anything that breaks determinism. But, for small code changes to Python, a reload should be fine, and allow me to hack code faster.