Skip to content

Commit b6d08c9

Browse files
committed
Refactor child and parent workflows with output models and service options
1 parent 737a1b9 commit b6d08c9

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

features/child_workflows/.env.Example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ BEARER_TOKEN=<your-bearer-token>
44
# Restack Cloud (Optional)
55

66
# RESTACK_ENGINE_ID=<your-engine-id>
7-
# RESTACK_ENGINE_API_KEY=<your-engine-api-key>
87
# RESTACK_ENGINE_ADDRESS=<your-engine-address>
9-
# RESTACK_CLOUD_TOKEN=<your-cloud-token>
8+
# RESTACK_ENGINE_API_KEY=<your-engine-api-key>
9+
# RESTACK_ENGINE_API_ADDRESS=<your-engine-api-address>

features/child_workflows/src/services.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
async def main():
1212
await client.start_service(
1313
workflows= [ParentWorkflow, ChildWorkflow],
14-
functions= [welcome],
15-
options=ServiceOptions(
16-
endpoints= True
17-
),
14+
functions= [welcome]
1815
)
1916

2017
def run_services():

features/child_workflows/src/workflows/child.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
class ChildInput(BaseModel):
99
name: str = "world"
1010

11+
class ChildOutput(BaseModel):
12+
result: str
13+
1114
@workflow.defn()
1215
class ChildWorkflow:
1316
@workflow.run
14-
async def run(self, input: ChildInput):
17+
async def run(self, input: ChildInput) -> ChildOutput:
1518
log.info("ChildWorkflow started")
1619
result = await workflow.step(welcome, input=input.name, start_to_close_timeout=timedelta(seconds=120))
1720
log.info("ChildWorkflow completed", result=result)
18-
return result
21+
return ChildOutput(result=result)

features/child_workflows/src/workflows/parent.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
class ParentInput(BaseModel):
66
child: bool = True
77

8+
class ParentOutput(BaseModel):
9+
result: str
10+
811
@workflow.defn()
912
class ParentWorkflow:
1013
@workflow.run
11-
async def run(self, input: ParentInput):
14+
async def run(self, input: ParentInput) -> ParentOutput:
1215
if input.child:
1316
# use the parent run id to create child workflow ids
1417
parent_workflow_id = workflow_info().workflow_id
@@ -19,8 +22,8 @@ async def run(self, input: ParentInput):
1922
log.info("Start ChildWorkflow and wait for result")
2023
result = await workflow.child_execute(ChildWorkflow, input=ChildInput(name="world"), workflow_id=f"{parent_workflow_id}-child-execute")
2124
log.info("ChildWorkflow completed", result=result)
22-
return "ParentWorkflow completed"
25+
return ParentOutput(result="ParentWorkflow completed")
2326

2427
else:
2528
log.info("ParentWorkflow without starting or executing child workflow")
26-
return "ParentWorkflow completed"
29+
return ParentOutput(result="ParentWorkflow completed")

0 commit comments

Comments
 (0)