Skip to content

Commit a402a19

Browse files
committed
RTU: ctx.start_workflow()
1 parent 82c0e54 commit a402a19

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

hello_nexus/basic/handler/service_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from nexusrpc.handler import StartOperationContext, service_handler, sync_operation
1010
from temporalio import nexus
11-
from temporalio.nexus import workflow_run_operation
11+
from temporalio.nexus import WorkflowRunOperationContext, workflow_run_operation
1212

1313
from hello_nexus.basic.handler.db_client import MyDBClient
1414
from hello_nexus.basic.handler.workflows import WorkflowStartedByNexusOperation
@@ -35,10 +35,10 @@ def __init__(self, connected_db_client: MyDBClient):
3535
# operation.
3636
@workflow_run_operation
3737
async def my_workflow_run_operation(
38-
self, ctx: StartOperationContext, input: MyInput
38+
self, ctx: WorkflowRunOperationContext, input: MyInput
3939
) -> nexus.WorkflowHandle[MyOutput]:
4040
# You could use self.connected_db_client here.
41-
return await nexus.start_workflow(
41+
return await ctx.start_workflow(
4242
WorkflowStartedByNexusOperation.run,
4343
input,
4444
id=str(uuid.uuid4()),

hello_nexus/without_service_definition/app.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
from typing import Optional
1111

1212
from nexusrpc.handler import (
13-
StartOperationContext,
1413
service_handler,
1514
)
1615
from temporalio import nexus, workflow
1716
from temporalio.client import Client
18-
from temporalio.nexus import workflow_run_operation
17+
from temporalio.nexus import WorkflowRunOperationContext, workflow_run_operation
1918
from temporalio.worker import UnsandboxedWorkflowRunner, Worker
2019
from temporalio.workflow import NexusClient
2120

@@ -40,14 +39,14 @@ async def run(self, message: str) -> str:
4039
@service_handler
4140
class MyNexusService:
4241
# Here we implement a Nexus operation backed by a Temporal workflow. The start
43-
# method must use nexus.start_workflow to start the workflow. (Temporal server will
44-
# then take care of delivering the workflow result to the caller, using the Nexus
45-
# RPC callback mechanism).
42+
# method must use WorkflowRunOperationContext.start_workflow to start the workflow.
43+
# (Temporal server will then take care of delivering the workflow result to the
44+
# caller, using the Nexus RPC callback mechanism).
4645
@workflow_run_operation
4746
async def my_workflow_run_operation(
48-
self, ctx: StartOperationContext, name: str
47+
self, ctx: WorkflowRunOperationContext, name: str
4948
) -> nexus.WorkflowHandle[str]:
50-
return await nexus.start_workflow(
49+
return await ctx.start_workflow(
5150
HandlerWorkflow.run,
5251
name,
5352
id=str(uuid.uuid4()),

0 commit comments

Comments
 (0)