How do I restart an opened workflow?

Currently I have a workflow that has been opened and it is still in progress.

Due to some business logic, I want to restart the workflow from the beginning using the same workflowId.

If I try to call WorkflowClient.start(…), I get the following error:
Caused by: io.grpc.StatusRuntimeException: ALREADY_EXISTS: Workflow execution is already running

Is there a way to restart a workflow? How do I do that with the Java SDK?

There are multiple ways to restart a workflow. You can either terminate the previous run and start it again.
Another option is to reset the workflow to its first workflow task.

Thanks for the reply, Maxim. Is there a way to restart it programmatically? Also terminate it programmatically?

All operations UI and CLI expose are going through gRPC APIs of the service. All of these APIs are available for user code as well.

For terminations you can use untyped workflow stub:

    WorkflowStub client =
        workflowClient.newUntypedWorkflowStub(workflowId, Optional.of(runId), Optional.empty());
    client.terminate("No reason");

Awesome. You mentioned there’s a reset workflow option through the CLI but I can’t seem to find that in the sdk-java. Could you point me to it? Thanks.

        WorkflowServiceStubs service =
            WorkflowServiceStubs.newInstance(
                WorkflowServiceStubsOptions.newBuilder().setTarget(serviceAddress).build());
        service.blockingStub().resetWorkflowExecution(request);

Hi @maxim,
I also need to restart a workflow by using Go SDK but I was not able to find the suggested method “untyped workflow stub” in the related SDK. Could you point me to the right code section?
Thanks in advance

It is not yet exposed in Go SDK. We are looking into it.

Any progress on this for the Go SDK?

We didn’t get to this yet. A contribution PR is welcome.

I will add ResetWorkflowExecution API to the Go SDK client.

1 Like

Here is the PR to track: Add ResetWorkflowExecution method to the client by alexshtin · Pull Request #400 · temporalio/sdk-go · GitHub.

1 Like

Hi Maxim. How do i create request object which is passed to resetWorkflowExecution method.
Is there any jar i need to download for Java to create object of ResetWorfklowExecutionRequest. Please help

WorkflowServiceStubs service =
        WorkflowServiceStubs.newInstance(
            WorkflowServiceStubsOptions.newBuilder().setTarget(serviceAddress).build());
    ResetWorkflowExecutionRequest request =
        ResetWorkflowExecutionRequest.newBuilder()
            ...
            .build();
    service.blockingStub(). resetWorkflowExecution(request);