@@ -60,23 +60,6 @@ def my_workflow_run_operation(
6060 return MyWorkflowRunOperation ()
6161
6262
63- # This is a Nexus operation that responds synchronously to all requests.
64- class MySyncOperation (SyncOperationHandler [MyInput , MyOutput ]):
65- # You can add an __init__ method taking any required arguments, since you are in
66- # control of instantiating the OperationHandler inside the operation handler method
67- # above decorated with @operation_handler.
68-
69- # Unlike the workflow run operation below, the `start` method for a sync operation
70- # returns the final operation result. Sync operations are free to make arbitrary
71- # network calls, or perform CPU-bound computations. Total execution duration must not
72- # exceed 10s. async def start(
73- async def start (
74- self , ctx : StartOperationContext , input : MyInput
75- ) -> StartOperationResultSync [MyOutput ]:
76- output = MyOutput (message = f"Hello { input .name } from sync operation!" )
77- return StartOperationResultSync (output )
78-
79-
8063# This is a Nexus operation that is backed by a Temporal workflow. That means that it
8164# responds asynchronously to all requests: it starts a workflow and responds with a token
8265# that the handler can associate with the worklow is started.
@@ -101,3 +84,29 @@ async def start(
10184 id = str (uuid .uuid4 ()),
10285 )
10386 return StartOperationResultAsync (token .encode ())
87+
88+
89+ # This is a Nexus operation that responds synchronously to all requests. That means that
90+ # unlike the workflow run operation above, in this case the `start` method returns the
91+ # final operation result.
92+ #
93+ # Here it is implemented by subclassing SyncOperationHandler and overriding the start
94+ # method. See service_handler.py for an alternative style using
95+ # SyncOperationHandler.from_callable.
96+ #
97+ # Sync operations are free to make arbitrary network calls, or perform CPU-bound
98+ # computations. Total execution duration must not exceed 10s.
99+ class MySyncOperation (SyncOperationHandler [MyInput , MyOutput ]):
100+ # You can add an __init__ method taking any required arguments, since you are in
101+ # control of instantiating the OperationHandler inside the operation handler method
102+ # above decorated with @operation_handler.
103+
104+ # Unlike the workflow run operation below, the `start` method for a sync operation
105+ # returns the final operation result. Sync operations are free to make arbitrary
106+ # network calls, or perform CPU-bound computations. Total execution duration must not
107+ # exceed 10s. async def start(
108+ async def start (
109+ self , ctx : StartOperationContext , input : MyInput
110+ ) -> StartOperationResultSync [MyOutput ]:
111+ output = MyOutput (message = f"Hello { input .name } from sync operation!" )
112+ return StartOperationResultSync (output )
0 commit comments