How to set a Parent Close Policy in PHP
In PHP, a Parent Close Policy is set via the ChildWorkflowOptions
object and withParentClosePolicy()
method.
The possible values can be obtained from the ParentClosePolicy
class.
POLICY_TERMINATE
POLICY_ABANDON
POLICY_REQUEST_CANCEL
Then ChildWorkflowOptions
object is used to create a new child workflow object:
$child = Workflow::newUntypedChildWorkflowStub(
'child-workflow',
ChildWorkflowOptions::new()
->withParentClosePolicy(ParentClosePolicy::POLICY_ABANDON)
);
yield $child->start();
In the snippet above we:
- Create a new untyped child workflow stub with
Workflow::newUntypedChildWorkflowStub
. - Provide
ChildWorkflowOptions
object with Parent Close Policy set toParentClosePolicy::POLICY_ABANDON
. - Start Child Workflow Execution asynchronously using
yield
and methodstart()
.
We need yield
here to ensure that a Child Workflow Execution starts before the parent closes.