javacadence-workflowuber-cadence

how to reset a cadence workflow with client sdk?


i have a cadence workflow with 3 activities. Scenario. the first activity is completed while executing second, the workflow failed after retry limit reached. now the problem has been fixed. how can i restart the failed workflow.

i have read this question related question.

i want to know that how can i use reset API in java client sdk to implement it.

cadence-dependence: compile group: 'com.uber.cadence', name: 'cadence-client', version: '3.5.0'

thanks for any help.


Solution

  • inside the WorkflowServiceTChannel class I found a method ResetWorkflowExecution. through it reset can be acheieved. code show as blow:

    public void testReset(String workflowid, String runid, String completeid){
    WorkflowClient workflowClient = WorkflowClient.newInstance( new WorkflowServiceTChannel( ClientOptions.newBuilder().setHost("127.0.0.1").setPort(8080).setFeatureFlags(new FeatureFlags().setWorkflowExecutionAlreadyCompletedErrorEnabled(true)).build()), WorkflowClientOptions.newBuilder().setDomain("domain-test").build());
    ResetWorkflowExecutionRequest request = new ResetWorkflowExecutionRequest();
    WorkflowExecution workflowExecution = new WorkflowExecution();
    workflowExecution.setWorkflowId(workflowid);
    workflowExecution.setRunId(runid);
    request.setRequestId(UUID.randomUUID().toString());
    request.setDomain("domain-test");
    request.setDecisionFinishEventId(Long.valueOf(completeid));
    request.setWorkflowExecution(workflowExecution);
    try {
    workflowClient.getService().ResetWorkflowExecution(request);
    } catch (TException e) {
    e.printStackTrace();
    }
    }