Workflow versioning to exclude an activity from workflows triggered in future

Hi all,

I have the following code snippet:

activity1.function1();
Workflow.await(() -> ...); // The workflow waits until a signal is received
activity2.function2();

I triggers a workflow, let’s call it workflow1.
workflow1 is waiting for the signal.

Now, I want to exclude activity2 for all the workflows triggered in future.

I do the following:

activity1.function1();
Workflow.await(() -> ...);
int version = Workflow.getVersion("excludeActivity2", Workflow.DEFAULT_VERSION, 1);
if (version == 1) {
    log.info("Activity 2 excluded.");
} else {
    activity2.function2();
}

After re-running my application, I triggers another workflow, let’s call it workflow2.
workflow2 is also waiting for the signal.

Then I send signals to both workflow1 and workflow2.

But both workflow1 and workflow2 executes the if part, i.e., “Activity 2 excluded.” is printed.

Am I missing something while versioning?
How can I make sure only workflow1 executes activity2.function2();?
Temporal version used is 1.23.2

Thanks,
Joe

Workflow.getVersion is evaluated at the time of the call. This allows fixing bugs in the already running workflows. I’m not sure why you want the workflow that started before still execute the old logic.

If you indeed want to fix the workflow version at the beginning of the workflow execution, call getVersion at the top of the workflow function.

1 Like

Thanks a lot for the solution, @maxim. Calling getVersion() at the top of the workflow did the trick.