Skip to content

Commit b7329d0

Browse files
committed
Delete operations-as-classes sample
1 parent 41c602e commit b7329d0

3 files changed

Lines changed: 21 additions & 178 deletions

File tree

hello_nexus/basic/handler/service_handler_with_operation_handler_classes.py

Lines changed: 0 additions & 141 deletions
This file was deleted.

hello_nexus/basic/handler/worker.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
from hello_nexus.basic.handler.db_client import MyDBClient
99
from hello_nexus.basic.handler.service_handler import MyNexusServiceHandler
10-
from hello_nexus.basic.handler.service_handler_with_operation_handler_classes import (
11-
MyNexusServiceHandlerUsingOperationHandlerClasses,
12-
)
1310
from hello_nexus.basic.handler.workflows import WorkflowStartedByNexusOperation
1411

1512
interrupt_event = asyncio.Event()
@@ -18,12 +15,7 @@
1815
TASK_QUEUE = "my-handler-task-queue"
1916

2017

21-
async def main(
22-
client: Optional[Client] = None,
23-
# Change this to use the service handler defined in
24-
# hello_nexus/basic/handler/service_handler_with_operation_handler_classes.py
25-
use_operation_handler_classes: bool = False,
26-
):
18+
async def main(client: Optional[Client] = None):
2719
logging.basicConfig(level=logging.INFO)
2820

2921
client = client or await Client.connect(
@@ -36,14 +28,6 @@ async def main(
3628
# requests. In this example we provide a database client object to the service hander.
3729
connected_db_client = MyDBClient.connect()
3830

39-
my_nexus_service_handler = (
40-
MyNexusServiceHandlerUsingOperationHandlerClasses(
41-
connected_db_client=connected_db_client
42-
)
43-
if use_operation_handler_classes
44-
else MyNexusServiceHandler(connected_db_client=connected_db_client)
45-
)
46-
4731
# Start the worker, passing the Nexus service handler instance, in addition to the
4832
# workflow classes that are started by your nexus operations, and any activities
4933
# needed. This Worker will poll for both workflow tasks and Nexus tasks (this example
@@ -52,7 +36,9 @@ async def main(
5236
client,
5337
task_queue=TASK_QUEUE,
5438
workflows=[WorkflowStartedByNexusOperation],
55-
nexus_service_handlers=[my_nexus_service_handler],
39+
nexus_service_handlers=[
40+
MyNexusServiceHandler(connected_db_client=connected_db_client)
41+
],
5642
):
5743
logging.info("Worker started, ctrl+c to exit")
5844
await interrupt_event.wait()

tests/hello_nexus/basic_test.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,25 @@ async def test_nexus_service_basic(client: Client):
1616
client=client,
1717
)
1818
try:
19-
for use_operation_handler_classes in [True, False]:
20-
handler_worker_task = asyncio.create_task(
21-
hello_nexus.basic.handler.worker.main(
22-
client,
23-
use_operation_handler_classes=use_operation_handler_classes,
24-
)
25-
)
26-
await asyncio.sleep(1)
27-
results = await hello_nexus.basic.caller.app.execute_caller_workflow(
19+
handler_worker_task = asyncio.create_task(
20+
hello_nexus.basic.handler.worker.main(
2821
client,
2922
)
30-
hello_nexus.basic.handler.worker.interrupt_event.set()
31-
await handler_worker_task
32-
hello_nexus.basic.handler.worker.interrupt_event.clear()
33-
print("\n\n")
34-
print([r.message for r in results])
35-
print("\n\n")
36-
assert [r.message for r in results] == [
37-
"Hello world from sync operation!",
38-
"Hello world from workflow run operation!",
39-
]
23+
)
24+
await asyncio.sleep(1)
25+
results = await hello_nexus.basic.caller.app.execute_caller_workflow(
26+
client,
27+
)
28+
hello_nexus.basic.handler.worker.interrupt_event.set()
29+
await handler_worker_task
30+
hello_nexus.basic.handler.worker.interrupt_event.clear()
31+
print("\n\n")
32+
print([r.message for r in results])
33+
print("\n\n")
34+
assert [r.message for r in results] == [
35+
"Hello world from sync operation!",
36+
"Hello world from workflow run operation!",
37+
]
4038
finally:
4139
await delete_nexus_endpoint(
4240
id=create_response.endpoint.id,

0 commit comments

Comments
 (0)