Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Asynchronous child workflow execution problem #532

Open
Muz4k opened this issue Dec 3, 2024 · 2 comments
Open

[Question] Asynchronous child workflow execution problem #532

Muz4k opened this issue Dec 3, 2024 · 2 comments
Labels
Question Further information is requested

Comments

@Muz4k
Copy link

Muz4k commented Dec 3, 2024

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
            },
);
@roxblnfk
Copy link
Collaborator

roxblnfk commented Dec 9, 2024

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
    },
);

@roxblnfk
Copy link
Collaborator

roxblnfk commented Dec 9, 2024

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();

@roxblnfk roxblnfk added Question Further information is requested and removed enhancement labels Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants