@@ -20,16 +20,19 @@ class directly.
2020
2121import uuid
2222
23+ from nexusrpc import OperationInfo
2324from nexusrpc .handler import (
25+ CancelOperationContext ,
26+ FetchOperationInfoContext ,
27+ FetchOperationResultContext ,
2428 OperationHandler ,
2529 StartOperationContext ,
2630 StartOperationResultAsync ,
2731 StartOperationResultSync ,
28- SyncOperationHandler ,
2932 operation_handler ,
3033 service_handler ,
3134)
32- from temporalio . nexus . handler import WorkflowRunOperationHandler , start_workflow
35+ from temporalio import nexus
3336
3437from hello_nexus .basic .handler .db_client import MyDBClient
3538from hello_nexus .basic .handler .service_handler import MyInput , MyNexusService , MyOutput
@@ -63,7 +66,7 @@ def my_workflow_run_operation(
6366# This is a Nexus operation that is backed by a Temporal workflow. That means that it
6467# responds asynchronously to all requests: it starts a workflow and responds with a token
6568# that the handler can associate with the worklow is started.
66- class MyWorkflowRunOperation (WorkflowRunOperationHandler [MyInput , MyOutput ]):
69+ class MyWorkflowRunOperation (OperationHandler [MyInput , MyOutput ]):
6770 # You can add an __init__ method taking any required arguments, since you are in
6871 # control of instantiating the OperationHandler inside the operation handler method
6972 # above decorated with @operation_handler.
@@ -78,12 +81,25 @@ class MyWorkflowRunOperation(WorkflowRunOperationHandler[MyInput, MyOutput]):
7881 async def start (
7982 self , ctx : StartOperationContext , input : MyInput
8083 ) -> StartOperationResultAsync :
81- token = await start_workflow (
84+ handle = await nexus . start_workflow (
8285 WorkflowStartedByNexusOperation .run ,
8386 input ,
8487 id = str (uuid .uuid4 ()),
8588 )
86- return StartOperationResultAsync (token .encode ())
89+ return StartOperationResultAsync (handle .to_token ())
90+
91+ async def fetch_info (
92+ self , ctx : FetchOperationInfoContext , input : MyInput
93+ ) -> OperationInfo :
94+ raise NotImplementedError
95+
96+ async def cancel (self , ctx : CancelOperationContext , input : MyInput ) -> None :
97+ raise NotImplementedError
98+
99+ async def fetch_result (
100+ self , ctx : FetchOperationResultContext , input : MyInput
101+ ) -> MyOutput :
102+ raise NotImplementedError
87103
88104
89105# This is a Nexus operation that responds synchronously to all requests. That means that
@@ -96,7 +112,7 @@ async def start(
96112#
97113# Sync operations are free to make arbitrary network calls, or perform CPU-bound
98114# computations. Total execution duration must not exceed 10s.
99- class MySyncOperation (SyncOperationHandler [MyInput , MyOutput ]):
115+ class MySyncOperation (OperationHandler [MyInput , MyOutput ]):
100116 # You can add an __init__ method taking any required arguments, since you are in
101117 # control of instantiating the OperationHandler inside the operation handler method
102118 # above decorated with @operation_handler.
@@ -110,3 +126,16 @@ async def start(
110126 ) -> StartOperationResultSync [MyOutput ]:
111127 output = MyOutput (message = f"Hello { input .name } from sync operation!" )
112128 return StartOperationResultSync (output )
129+
130+ async def fetch_info (
131+ self , ctx : FetchOperationInfoContext , input : MyInput
132+ ) -> OperationInfo :
133+ raise NotImplementedError
134+
135+ async def cancel (self , ctx : CancelOperationContext , input : MyInput ) -> None :
136+ raise NotImplementedError
137+
138+ async def fetch_result (
139+ self , ctx : FetchOperationResultContext , input : MyInput
140+ ) -> MyOutput :
141+ raise NotImplementedError
0 commit comments