I want my parent workflow to call a long running child workflow asynchronously.
I want to keep it untype (for future flexibility). so here is what I am doing as per docs
val childUntyped = Workflow.newUntypedChildWorkflowStub(
workflowType,
ChildWorkflowOptions.newBuilder()
.setWorkflowId(workflowId)
.setTaskQueue(taskQueue)
.setParentClosePolicy(ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON)
.build()
)
val childExecution = childUntyped.executeAsync(
Unit.javaClass,
definition
)
// Important:This is to ensure that a Child Workflow Execution starts before the parent closes.
// If the parent initiates a Child Workflow Execution and then completes immediately after,
// the Child Workflow will never execute. Refer: https://docs.temporal.io/application-development/features?lang=java#parent-close-policy
childExecution.get()
log.info("Successfully Scheduled Child workflow")
both workflows are kicked off.
child workflow has a timer and is still running.
I expected the parent workflow to complete after the child workflow has started. but I see it is still waiting for the promise - childExecution.get()
I am not sure why the promise is not returned after child has started?
ChildWorkflowStub.executeAsync returns a Promise that becomes ready when a child workflow completes. Use ChildWorkflowStub.getExecution() to get a Promise that becomes ready when the child workflow starts.
@maxim if you are using ChildWorkflowStub.getExecution(), how would you pass a payload to the child workflow? With executeAsync, one of the arguments is args, which is where the WorkflowExecutionStarted data comes from I think, but I’m not seeing a way to do that with getExecution
Thanks @antonio.perez will try that! And now, however, SUPER struggling to unit test this behavior as well, since, the examples for unit testing parent-> child stuff do it with typed workflows…how would one unit test the untyped variety?
How do you properly kick off an UNTYPED child workflow, and get the parent workflow to report when the child workflow STARTED, but not stay open for the whole child execution, aka, have the parent be done when the child is certain that it is entered into temporal and/or started but not stay open. If it stays open, it makes our workflow slower, and its harder to measure the speed of each individual workflow. We don’t need the parent to stay open while the child executes
How do you unit test said behavior? When I wrote tests without doing this, they just hang. But I’m not sure also how to implement that example, with an UNTYPED child workflow
I guess then the child is running in a different taskqueue?
If you don’t need to test if the child is running, just remove registerWorkflowImplementationFactory and the asserts related to the child workflow from test code.
If you need to test the child is running after the parent has completed,
I think you still need an interface:
//worker listening in the child taskqueue
Worker workerChildTaskqueue =
testWorkflowRule.getTestEnvironment().newWorker("child-taskqueue");
// Factory is called to create a new workflow object on each workflow task.
workerChildTaskqueue.registerWorkflowImplementationFactory(
ChildWorkflow.class,
() -> {
ChildWorkflow child = mock(ChildWorkflow.class);
return child;
});
Note that the taskqueue for the worker running the child workflow in your case will be different (not "child-taskqueue")
or you can get the workflow history of the parent workflow and look for the eventType = ChildWorkflowExecutionStarted