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 dd18b71
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,23 @@ protected void executeCancellation() {
.build();
DescribeWorkflowExecutionResponse response = workflowServiceStubs.blockingStub().describeWorkflowExecution(request);

// 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 &&
status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_TERMINATED) {
try {
// 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 &&
status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_TERMINATED) {
workflowStub.cancel();
log.info("Temporal workflow {} cancelled successfully", this.workflowId);
} else {
log.info("Workflow {} is already finished with status {}", this.workflowId, status);
}
}
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);
} else {
log.info("Workflow {} is already finished with status {}", this.workflowId, status);
}
}
catch (Exception e) {
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 dd18b71

Please sign in to comment.