Skip to content

Commit 51ff73a

Browse files
Fix lint issues
1 parent 0a52e2c commit 51ff73a

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

nexus_cancel/caller/workflows.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,6 @@ def __init__(self):
3232
self.nexus_client = workflow.create_nexus_client(
3333
service=MyNexusService,
3434
endpoint=NEXUS_ENDPOINT,
35-
# Set the cancellation type to WAIT_REQUESTED. This means that the caller
36-
# will wait for the cancellation request to be received by the handler before
37-
# proceeding with the cancellation.
38-
#
39-
# By default, the caller would wait until the operation is completed.
40-
operation_options=workflow.NexusOperationOptions(
41-
schedule_to_close_timeout=timedelta(seconds=10),
42-
cancellation_type=workflow.NexusOperationCancellationType.WAIT_REQUESTED,
43-
),
4435
)
4536

4637
@workflow.run
@@ -58,19 +49,30 @@ async def run(self, message: str) -> str:
5849
names = ["Nexus-1", "Nexus-2", "Nexus-3", "Nexus-4", "Nexus-5"]
5950

6051
# Create a list to store operation tasks
61-
tasks = []
52+
tasks: list[asyncio.Task[MyOutput]] = []
53+
54+
async def await_operation_result(
55+
op_handle: workflow.NexusOperationHandle[MyOutput],
56+
) -> MyOutput:
57+
return await op_handle
6258

6359
# Create our cancellation scope. Within this scope we call the nexus operation
6460
# asynchronously for each name.
6561
async def start_operations():
6662
for name in names:
6763
# Start each operation asynchronously
64+
# Set the cancellation type to WAIT_REQUESTED. This means that the
65+
# caller will wait for the cancellation request to be received by the
66+
# handler before proceeding with the cancellation.
67+
# By default, the caller would wait until the operation is completed.
6868
handle = await self.nexus_client.start_operation(
6969
MyNexusService.my_workflow_run_operation,
7070
MyInput(name),
71+
schedule_to_close_timeout=timedelta(seconds=10),
72+
cancellation_type=workflow.NexusOperationCancellationType.WAIT_REQUESTED,
7173
)
7274
# Create a task that waits for the operation result
73-
tasks.append(asyncio.create_task(handle))
75+
tasks.append(asyncio.create_task(await_operation_result(handle)))
7476

7577
# Execute all nexus operations within a try block so we can cancel them
7678
try:

nexus_cancel/handler/service_handler.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
from __future__ import annotations
1010

11-
import uuid
12-
1311
import nexusrpc
1412
from temporalio import nexus
1513

nexus_cancel/handler/worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async def main():
3131
task_queue=TASK_QUEUE,
3232
workflows=[HelloHandlerWorkflow],
3333
# The nexus_services parameter registers the Nexus service handler
34-
nexus_services=[service_handler],
34+
nexus_service_handlers=[service_handler],
3535
)
3636

3737
print(

0 commit comments

Comments
 (0)