Skip to content

Commit 3ecd5fe

Browse files
committed
Edits, imports
1 parent ebfe025 commit 3ecd5fe

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

hello_nexus/caller/workflows.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@
66
NEXUS_ENDPOINT = "hello-nexus-basic-nexus-endpoint"
77

88

9-
# This is a workflow that calls a nexus operation.
9+
# This is a workflow that calls two nexus operations.
1010
@workflow.defn
1111
class CallerWorkflow:
12-
# An __init__ method is always optional on a Workflow class. Here we use it to set the
13-
# NexusClient, but that could alternatively be done in the run method.
12+
# An __init__ method is always optional on a workflow class. Here we use it to set the
13+
# nexus client, but that could alternatively be done in the run method.
1414
def __init__(self):
1515
self.nexus_client = workflow.create_nexus_client(
1616
service=MyNexusService,
1717
endpoint=NEXUS_ENDPOINT,
1818
)
1919

20-
# The Wokflow run method invokes two Nexus operations.
20+
# The workflow run method invokes two nexus operations.
2121
@workflow.run
2222
async def run(self, name: str) -> tuple[MyOutput, MyOutput]:
23-
# Start the Nexus operation and wait for the result in one go, using execute_operation.
23+
# Start the nexus operation and wait for the result in one go, using execute_operation.
2424
wf_result = await self.nexus_client.execute_operation(
2525
MyNexusService.my_workflow_run_operation,
2626
MyInput(name),
2727
)
28-
# We could use execute_operation for this one also, but here we demonstrate
29-
# obtaining the operation handle and then using it to get the result.
28+
# Alternatively, you can use start_operation to obtain the operation handle and
29+
# then `await` the handle to obtain the result.
3030
sync_operation_handle = await self.nexus_client.start_operation(
3131
MyNexusService.my_sync_operation,
3232
MyInput(name),

hello_nexus/handler/service_handler.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66

77
import uuid
88

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

1312
from hello_nexus.handler.workflows import WorkflowStartedByNexusOperation
1413
from hello_nexus.service import MyInput, MyNexusService, MyOutput
1514

1615

17-
@service_handler(service=MyNexusService)
16+
@nexusrpc.handler.service_handler(service=MyNexusService)
1817
class MyNexusServiceHandler:
1918
# You can create an __init__ method accepting what is needed by your operation
2019
# handlers to handle requests. You typically instantiate your service handler class
@@ -27,9 +26,9 @@ class MyNexusServiceHandler:
2726
#
2827
# The token will be used by the caller if it subsequently wants to cancel the Nexus
2928
# operation.
30-
@workflow_run_operation
29+
@nexus.workflow_run_operation
3130
async def my_workflow_run_operation(
32-
self, ctx: WorkflowRunOperationContext, input: MyInput
31+
self, ctx: nexus.WorkflowRunOperationContext, input: MyInput
3332
) -> nexus.WorkflowHandle[MyOutput]:
3433
return await ctx.start_workflow(
3534
WorkflowStartedByNexusOperation.run,
@@ -43,8 +42,8 @@ async def my_workflow_run_operation(
4342
#
4443
# Sync operations are free to make arbitrary network calls, or perform CPU-bound
4544
# computations. Total execution duration must not exceed 10s.
46-
@sync_operation
45+
@nexusrpc.handler.sync_operation
4746
async def my_sync_operation(
48-
self, ctx: StartOperationContext, input: MyInput
47+
self, ctx: nexusrpc.handler.StartOperationContext, input: MyInput
4948
) -> MyOutput:
5049
return MyOutput(message=f"Hello {input.name} from sync operation!")

0 commit comments

Comments
 (0)