Skip to main content

Child Workflows

A workflow can start other workflows as children. The parent can wait for the child to complete or fire-and-forget it and track it independently.

Execute and await

execute_child_workflow starts a child workflow and waits for its result:

from datetime import timedelta
from cadence.workflow import execute_child_workflow

@registry.workflow()
class ParentWorkflow:
@workflow.run
async def run(self, order_id: str) -> str:
result = await execute_child_workflow(
"ProcessOrderWorkflow", # child workflow type name
str, # expected return type
order_id, # argument to child
task_list="order-workers",
execution_start_to_close_timeout=timedelta(minutes=30),
)
return result

Start without immediately awaiting

start_child_workflow returns a ChildWorkflowFuture you can await later or signal before awaiting:

from cadence.workflow import start_child_workflow

@registry.workflow()
class ParentWorkflow:
@workflow.run
async def run(self) -> None:
future = await start_child_workflow(
"ChildWorkflow",
str,
task_list="child-workers",
execution_start_to_close_timeout=timedelta(hours=1),
)

# Send a signal before awaiting
await future.signal("start-processing")

result = await future

ChildWorkflowFuture

Method / PropertyDescription
await futureWait for the child to complete and return its result
future.workflow_idThe child's workflow ID
future.run_idThe child's run ID
future.cancel()Request cancellation of the child
await future.signal(name, *args)Send a signal to the child

Child workflow options

OptionDescription
workflow_idID for the child execution (auto-generated if omitted)
task_listTask list for the child worker
execution_start_to_close_timeoutMax total duration
task_start_to_close_timeoutMax time per decision task
retry_policyRetry policy for the child
cron_scheduleRun the child as a recurring cron workflow
domainDomain for the child (defaults to parent's domain)
parent_close_policyWhat to do with the child when the parent closes
memoKey-value metadata attached to the child execution

Parent close policy

parent_close_policy controls what happens to the child when the parent workflow closes (completes, fails, or is cancelled):

from cadence.api.v1 import workflow_pb2

future = await start_child_workflow(
"ChildWorkflow",
str,
task_list="child-workers",
execution_start_to_close_timeout=timedelta(hours=1),
parent_close_policy=workflow_pb2.PARENT_CLOSE_POLICY_ABANDON,
)
PolicyBehavior
PARENT_CLOSE_POLICY_TERMINATE (default)Terminate the child
PARENT_CLOSE_POLICY_ABANDONLeave the child running
PARENT_CLOSE_POLICY_REQUEST_CANCELRequest cancellation of the child