in src/main/java/com/uber/cadence/internal/testservice/TestWorkflowMutableStateImpl.java [904:976]
private void processFailWorkflowExecution(
RequestContext ctx,
FailWorkflowExecutionDecisionAttributes d,
long decisionTaskCompletedId,
String identity)
throws InternalServiceError, BadRequestError {
WorkflowData data = workflow.getData();
if (data.retryState.isPresent()) {
RetryState rs = data.retryState.get();
int backoffIntervalSeconds =
rs.getBackoffIntervalInSeconds(d.getReason(), store.currentTimeMillis());
if (backoffIntervalSeconds > 0) {
ContinueAsNewWorkflowExecutionDecisionAttributes continueAsNewAttr =
new ContinueAsNewWorkflowExecutionDecisionAttributes()
.setInput(startRequest.getInput())
.setWorkflowType(startRequest.getWorkflowType())
.setExecutionStartToCloseTimeoutSeconds(
startRequest.getExecutionStartToCloseTimeoutSeconds())
.setTaskStartToCloseTimeoutSeconds(startRequest.getTaskStartToCloseTimeoutSeconds())
.setTaskList(startRequest.getTaskList())
.setBackoffStartIntervalInSeconds(backoffIntervalSeconds)
.setRetryPolicy(startRequest.getRetryPolicy());
workflow.action(Action.CONTINUE_AS_NEW, ctx, continueAsNewAttr, decisionTaskCompletedId);
HistoryEvent event = ctx.getEvents().get(ctx.getEvents().size() - 1);
WorkflowExecutionContinuedAsNewEventAttributes continuedAsNewEventAttributes =
event.getWorkflowExecutionContinuedAsNewEventAttributes();
Optional<RetryState> continuedRetryState = Optional.of(rs.getNextAttempt());
String runId =
service.continueAsNew(
startRequest,
continuedAsNewEventAttributes,
continuedRetryState,
identity,
getExecutionId(),
parent,
parentChildInitiatedEventId);
continuedAsNewEventAttributes.setNewExecutionRunId(runId);
return;
}
}
if (!Strings.isNullOrEmpty(data.cronSchedule)) {
startNewCronRun(ctx, decisionTaskCompletedId, identity, data, data.lastCompletionResult);
return;
}
workflow.action(StateMachines.Action.FAIL, ctx, d, decisionTaskCompletedId);
if (parent.isPresent()) {
ctx.lockTimer(); // unlocked by the parent
ChildWorkflowExecutionFailedEventAttributes a =
new ChildWorkflowExecutionFailedEventAttributes()
.setInitiatedEventId(parentChildInitiatedEventId.getAsLong())
.setDetails(d.getDetails())
.setReason(d.getReason())
.setWorkflowType(startRequest.getWorkflowType())
.setDomain(ctx.getDomain())
.setWorkflowExecution(ctx.getExecution());
ForkJoinPool.commonPool()
.execute(
() -> {
try {
parent
.get()
.childWorkflowFailed(ctx.getExecutionId().getWorkflowId().getWorkflowId(), a);
} catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) {
// Parent might already close
} catch (BadRequestError | InternalServiceError e) {
log.error("Failure reporting child completion", e);
}
});
}
}