in src/main/java/com/uber/cadence/internal/sync/SyncDecisionContext.java [400:458]
private Promise<byte[]> executeChildWorkflowOnce(
String name,
ChildWorkflowOptions options,
byte[] input,
CompletablePromise<WorkflowExecution> executionResult) {
RetryParameters retryParameters = null;
RetryOptions retryOptions = options.getRetryOptions();
if (retryOptions != null) {
retryParameters = new RetryParameters(retryOptions);
}
List<ContextPropagator> propagators = options.getContextPropagators();
if (propagators == null) {
propagators = this.contextPropagators;
}
StartChildWorkflowExecutionParameters parameters =
new StartChildWorkflowExecutionParameters.Builder()
.setWorkflowType(new WorkflowType().setName(name))
.setWorkflowId(options.getWorkflowId())
.setInput(input)
.setExecutionStartToCloseTimeoutSeconds(
options.getExecutionStartToCloseTimeout().getSeconds())
.setDomain(options.getDomain())
.setTaskList(options.getTaskList())
.setTaskStartToCloseTimeoutSeconds(options.getTaskStartToCloseTimeout().getSeconds())
.setWorkflowIdReusePolicy(options.getWorkflowIdReusePolicy())
.setRetryParameters(retryParameters)
.setCronSchedule(options.getCronSchedule())
.setMemo(options.getMemo())
.setSearchAttributes(options.getSearchAttributes())
.setContext(extractContextsAndConvertToBytes(propagators))
.setParentClosePolicy(options.getParentClosePolicy())
.build();
CompletablePromise<byte[]> result = Workflow.newPromise();
Consumer<Exception> cancellationCallback =
context.startChildWorkflow(
parameters,
(we) ->
runner.executeInWorkflowThread(
"child workflow completion callback", () -> executionResult.complete(we)),
(output, failure) -> {
if (failure != null) {
runner.executeInWorkflowThread(
"child workflow failure callback",
() -> result.completeExceptionally(mapChildWorkflowException(failure)));
} else {
runner.executeInWorkflowThread(
"child workflow completion callback", () -> result.complete(output));
}
});
CancellationScope.current()
.getCancellationRequest()
.thenApply(
(reason) -> {
cancellationCallback.accept(new CancellationException(reason));
return null;
});
return result;
}