[Question] Asynchronous child workflow execution problem
Hello!
(Sorry, I posted on the forum, but I really need to get a response as soon as possible) I’ve got a problem with child workflow working.
The child workflow is initialized, but the execution does not start
I assume that the problem is due to the fact that it does not have time to start execution - the parent workflow finishes faster.
I found a bestway for java - Best way to create an async child workflow that looks like the one I need
Point 4 says “Wait for the Promise returned by getWorkflowExecution to complete. ”
Can you please tell me how this can be implemented using php-sdk? My code now looks like this (called inside the parent workflow)
Workflow::asyncDetached(
task: static function (): void {
$options = ChildWorkflowOptions::new()
->withTaskQueue('task_name')
->withParentClosePolicy(ParentClosePolicy::Abandon);
$workflow = Workflow::newChildWorkflowStub(
class: MyChildWorkflowInterface::class,
options: $options,
);
$workflow->execute(); // workflow logic
},
);
Hi. Sorry for the delay.
Have you tried using yield to wait promises?
// Here:
yield Workflow::asyncDetached(
task: static function () {
$options = ChildWorkflowOptions::new()
->withTaskQueue('task_name')
->withParentClosePolicy(ParentClosePolicy::Abandon);
$workflow = Workflow::newChildWorkflowStub(
class: MyChildWorkflowInterface::class,
options: $options,
);
// And here:
yield $workflow->execute(); // workflow logic
},
);
I may have misunderstood your question.
If you want to simply run a Child Workflow in a Detached context (for example, after receiving a Cancel) and just complete the parent, UntypedChildWorkflowStub can help you, as it has a start() method.
You can obtain UntypedChildWorkflowStub via Workflow::newUntypedChildWorkflowStub(), and you can wait for the Child Workflow to start like this: yield $untypedStub->start();