@@ -21,21 +21,15 @@ class directly.
2121import uuid
2222
2323from nexusrpc .handler import (
24- CancelOperationContext ,
25- FetchOperationInfoContext ,
26- FetchOperationResultContext ,
2724 OperationHandler ,
28- OperationInfo ,
2925 StartOperationContext ,
3026 StartOperationResultAsync ,
3127 StartOperationResultSync ,
28+ SyncOperationHandler ,
3229 operation_handler ,
3330 service_handler ,
3431)
35- from temporalio .nexus .handler import (
36- cancel_operation ,
37- start_workflow ,
38- )
32+ from temporalio .nexus .handler import WorkflowRunOperationHandler , start_workflow
3933
4034from hello_nexus .basic .handler .db_client import MyDBClient
4135from hello_nexus .basic .handler .service_handler import MyInput , MyNexusService , MyOutput
@@ -67,7 +61,7 @@ def my_workflow_run_operation(
6761
6862
6963# This is a Nexus operation that responds synchronously to all requests.
70- class MySyncOperation (OperationHandler [MyInput , MyOutput ]):
64+ class MySyncOperation (SyncOperationHandler [MyInput , MyOutput ]):
7165 # You can add an __init__ method taking any required arguments, since you are in
7266 # control of instantiating the OperationHandler inside the operation handler method
7367 # above decorated with @operation_handler.
@@ -82,45 +76,16 @@ async def start(
8276 output = MyOutput (message = f"Hello { input .name } from sync operation!" )
8377 return StartOperationResultSync (output )
8478
85- async def fetch_info (
86- self ,
87- ctx : FetchOperationInfoContext ,
88- token : str ,
89- ) -> OperationInfo :
90- raise NotImplementedError (
91- "fetch_info is not supported when a Nexus operation is called by a Temporal workflow"
92- )
93-
94- async def fetch_result (
95- self ,
96- ctx : FetchOperationResultContext ,
97- token : str ,
98- ) -> MyOutput :
99- raise NotImplementedError (
100- "fetch_result is not supported when a Nexus operation is called by a Temporal workflow, "
101- "but this sample does not demonstrate result fetching"
102- )
103-
104- async def cancel (
105- self ,
106- ctx : CancelOperationContext ,
107- token : str ,
108- ) -> None :
109- raise NotImplementedError (
110- "cancel is supported when a Nexus operation is called by a Temporal workflow, "
111- "but this sample does not demonstrate cancellation"
112- )
113-
11479
11580# This is a Nexus operation that is backed by a Temporal workflow. That means that it
11681# responds asynchronously to all requests: it starts a workflow and responds with a token
11782# that the handler can associate with the worklow is started.
118- class MyWorkflowRunOperation (OperationHandler [MyInput , MyOutput ]):
83+ class MyWorkflowRunOperation (WorkflowRunOperationHandler [MyInput , MyOutput ]):
11984 # You can add an __init__ method taking any required arguments, since you are in
12085 # control of instantiating the OperationHandler inside the operation handler method
12186 # above decorated with @operation_handler.
12287
123- # The start method starts a workflow, and returns a WorkflowRunOperationResult that it
88+ # The start method starts a workflow, and returns a StartOperationResultAsync that it
12489 # creates from the workflow handle. This return value contains the Nexus operation
12590 # token that the handler can use to obtain a handle and interact with the workflow on
12691 # future requests (for example if a cancel request is subsequently sent by the
@@ -136,21 +101,3 @@ async def start(
136101 id = str (uuid .uuid4 ()),
137102 )
138103 return StartOperationResultAsync (token .encode ())
139-
140- async def cancel (self , ctx : CancelOperationContext , token : str ) -> None :
141- return await cancel_operation (token )
142-
143- async def fetch_info (
144- self , ctx : FetchOperationInfoContext , token : str
145- ) -> OperationInfo :
146- raise NotImplementedError (
147- "fetch_info is not supported when a Nexus operation is called by a Temporal workflow"
148- )
149-
150- async def fetch_result (
151- self , ctx : FetchOperationResultContext , token : str
152- ) -> MyOutput :
153- raise NotImplementedError (
154- "fetch_result is not supported when a Nexus operation is called by a Temporal workflow, "
155- "but this sample does not demonstrate result fetching"
156- )
0 commit comments