Skip to content

Commit a9927e9

Browse files
committed
Cleanup
1 parent 6467b77 commit a9927e9

2 files changed

Lines changed: 39 additions & 25 deletions

File tree

hello_nexus/basic/handler/service_handler.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ def __init__(self, connected_db_client: MyDBClient):
4343
self.connected_db_client = connected_db_client
4444

4545
# This is a nexus operation that is backed by a Temporal workflow. The start method
46-
# starts a workflow, and returns a nexus operation token synchronously. Meanwhile,
47-
# the workflow executes in the background, and the Temporal server takes care of
48-
# delivering the eventual workflow result (success or failure) to the calling
49-
# workflow.
46+
# starts a workflow, and returns a nexus operation token. Meanwhile, the workflow
47+
# executes in the background; Temporal server takes care of delivering the eventual
48+
# workflow result (success or failure) to the calling workflow.
5049
#
5150
# The token will be used by the caller if it subsequently wants to cancel the Nexus
5251
# operation.
@@ -66,10 +65,16 @@ async def start(
6665

6766
return WorkflowRunOperationHandler.from_callable(start)
6867

69-
# This is a sync operation. That means that unlike the workflow run operation above,
70-
# in this case the `start` method returns the final operation result. Sync operations
71-
# are free to make arbitrary network calls, or perform CPU-bound computations. Total
72-
# execution duration must not exceed 10s.
68+
# This is a Nexus operation that responds synchronously to all requests. That means
69+
# that unlike the workflow run operation above, in this case the `start` method
70+
# returns the final operation result.
71+
#
72+
# Here it is implemented using SyncOperationHandler.from_callable.
73+
# See service_handler_with_operation_handler_classes.py for an alternative style
74+
# involving subclassing SyncOperationHandler and overriding the start method.
75+
#
76+
# Sync operations are free to make arbitrary network calls, or perform CPU-bound
77+
# computations. Total execution duration must not exceed 10s.
7378
@operation_handler
7479
def my_sync_operation(
7580
self,

hello_nexus/basic/handler/service_handler_with_operation_handler_classes.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)