Skip to content

Commit

Permalink
Ignore exceptions while fetching workflow status
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekmjain committed Sep 4, 2024
1 parent 2f955e7 commit f3f61d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,19 @@ protected void executeCancellation() {
.build();
DescribeWorkflowExecutionResponse response = workflowServiceStubs.blockingStub().describeWorkflowExecution(request);

WorkflowExecutionStatus status;
try {
status = response.getWorkflowExecutionInfo().getStatus();
}
catch (Exception e) {
log.warn("Exception occurred while getting status of the workflow " + this.workflowId
+ ". We would still attempt the cancellation", e);
workflowStub.cancel();
log.info("Temporal workflow {} cancelled successfully", this.workflowId);
return;
}

// Check if the workflow is not finished
WorkflowExecutionStatus status = response.getWorkflowExecutionInfo().getStatus();
if (status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_COMPLETED &&
status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_FAILED &&
status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_CANCELED &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,16 @@ public void testCancelWorkflowIfRunning() throws Exception {

verify(mockStub, times(1)).cancel();
}

@Test
public void testCancelWorkflowFetchStatusThrowsException() throws Exception {
// Mock the get workflow status to throw an exception
Mockito.doThrow(new RuntimeException("Some exception occurred")).when(mockExecutionInfo).getStatus();

jobLauncher.submitJob(null);

jobLauncher.executeCancellation();

verify(mockStub, times(1)).cancel();
}
}

0 comments on commit f3f61d6

Please sign in to comment.