in src/main/java/com/uber/cadence/internal/testservice/TestWorkflowMutableStateImpl.java [1135:1194]
public void startWorkflow(
boolean continuedAsNew, Optional<SignalWorkflowExecutionRequest> signalWithStartSignal)
throws InternalServiceError, BadRequestError {
try {
update(
ctx -> {
workflow.action(StateMachines.Action.START, ctx, startRequest, 0);
if (signalWithStartSignal.isPresent()) {
addExecutionSignaledEvent(ctx, signalWithStartSignal.get());
}
int backoffStartIntervalInSeconds = workflow.getData().backoffStartIntervalInSeconds;
if (backoffStartIntervalInSeconds > 0) {
ctx.addTimer(
backoffStartIntervalInSeconds,
() -> {
try {
update(ctx1 -> scheduleDecision(ctx1));
} catch (EntityNotExistsError e) {
// Expected as timers are not removed
} catch (Exception e) {
// Cannot fail to timer threads
log.error("Failure trying to add task for an delayed workflow retry", e);
}
},
"delayedFirstDecision");
} else {
scheduleDecision(ctx);
}
int executionTimeoutTimerDelay = startRequest.getExecutionStartToCloseTimeoutSeconds();
if (backoffStartIntervalInSeconds > 0) {
executionTimeoutTimerDelay =
executionTimeoutTimerDelay + backoffStartIntervalInSeconds;
}
ctx.addTimer(
executionTimeoutTimerDelay, this::timeoutWorkflow, "workflow execution timeout");
});
} catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) {
throw new InternalServiceError(Throwables.getStackTraceAsString(e));
}
if (!continuedAsNew && parent.isPresent()) {
ChildWorkflowExecutionStartedEventAttributes a =
new ChildWorkflowExecutionStartedEventAttributes()
.setInitiatedEventId(parentChildInitiatedEventId.getAsLong())
.setWorkflowExecution(getExecutionId().getExecution())
.setDomain(getExecutionId().getDomain())
.setWorkflowType(startRequest.getWorkflowType());
ForkJoinPool.commonPool()
.execute(
() -> {
try {
parent.get().childWorkflowStarted(a);
} catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) {
// Not a problem. Parent might just close by now.
} catch (BadRequestError | InternalServiceError e) {
log.error("Failure reporting child completion", e);
}
});
}
}