Resuming a failed workflow from the point of failure

Hi team, I am a newbie. Would someone please help me understand if my workflow has 7 steps (activities). Workflow got failed while executing 5th one.
How do I resume my workflow from the same point of failure.
Please help me with java code example.

The simplest approach is to not fail the workflow on activity failure. Just keep retrying the activity until it is fixed.

If you really need to restart the failed workflow you use the reset feature.

1 Like

I have gone through some other tickets. Found this way to restart the workflow from the point of failure.
Let me know if I am doing it correctly :slight_smile:

RESET WORKFLOW USING THE SAME WORKFLOW ID :

ResetWorkflowExecutionRequest request = ResetWorkflowExecutionRequest.newBuilder().setNamespace(namespace)
.setWorkflowExecution(WorkflowExecution.newBuilder().setWorkflowId(workflowId).build())
.setWorkflowTaskFinishEventId(tid)
.setReason(“reset”)
.build();

CODE TO FIND THE HISTORY OF EVENTS OF A WORKFLOW :

WorkflowServiceStubs service = WorkflowServiceStubs.newInstance();

GetWorkflowExecutionHistoryResponse result =
    service
        .blockingStub()
        .getWorkflowExecutionHistory(
            GetWorkflowExecutionHistoryRequest.newBuilder()
                .setNamespace(namespace)
                .setExecution(WorkflowExecution.newBuilder().setWorkflowId(workflowId).build())
                .build());

CODE TO FIND THE LAST SUCCESSFUL EVENTID :

for (HistoryEvent e : history.getEventsList()){
//TODO : paginated history events list
if(e.getEventType() == EventType.EVENT_TYPE_ACTIVITY_TASK_FAILED)
break;
if(e.getEventType() == EventType.EVENT_TYPE_WORKFLOW_TASK_STARTED)
tid = e.getEventId();
}

For use case I think you are looking to find the last completed workflow task as the reset point. Could reference how tctl does it here, its Go code but think easy to read to get idea.

I tried the code but got the error:

io.temporal.failure.ActivityFailure: scheduledEventId=35, startedEventId=36, activityType='WaitJenkins', activityId='3fea59fa-d703-39d5-8612-4491a62f2ac7', identity='1@zcp-console-dev-main-va1-meta-5f4f5fb684-q7cqs', retryState=RETRY_STATE_NON_RETRYABLE_FAILURE

So how can I retry if the activity state is RETRY_STATE_NON_RETRYABLE_FAILURE

Could you give more info please? Assume you did reset to a workflow task before “WaitJenkins” activity and it failed on the new created execution? Is your activity throwing a non-retryable error from its code?

yes, the activity threw a non-retryable error.

So the reset method won’t reset this error right?