Skip to content

Commit 4fa118d

Browse files
committed
Don't demonstrate passing in a db client
1 parent 5788300 commit 4fa118d

3 files changed

Lines changed: 1 addition & 40 deletions

File tree

hello_nexus/handler/db_client.py

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

hello_nexus/handler/service_handler.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from temporalio import nexus
1111
from temporalio.nexus import WorkflowRunOperationContext, workflow_run_operation
1212

13-
from hello_nexus.handler.db_client import MyDBClient
1413
from hello_nexus.handler.workflows import WorkflowStartedByNexusOperation
1514
from hello_nexus.service import MyInput, MyNexusService, MyOutput
1615

@@ -20,11 +19,6 @@ class MyNexusServiceHandler:
2019
# You can create an __init__ method accepting what is needed by your operation
2120
# handlers to handle requests. You typically instantiate your service handler class
2221
# when starting your worker. See hello_nexus/basic/handler/worker.py.
23-
def __init__(self, connected_db_client: MyDBClient):
24-
# `connected_db_client` is intended as an example of something that might be
25-
# required by your operation handlers when handling requests, but is only
26-
# available at worker-start time.
27-
self.connected_db_client = connected_db_client
2822

2923
# This is a nexus operation that is backed by a Temporal workflow. The start method
3024
# starts a workflow, and returns a nexus operation token. Meanwhile, the workflow
@@ -37,7 +31,6 @@ def __init__(self, connected_db_client: MyDBClient):
3731
async def my_workflow_run_operation(
3832
self, ctx: WorkflowRunOperationContext, input: MyInput
3933
) -> nexus.WorkflowHandle[MyOutput]:
40-
# You could use self.connected_db_client here.
4134
return await ctx.start_workflow(
4235
WorkflowStartedByNexusOperation.run,
4336
input,
@@ -54,5 +47,4 @@ async def my_workflow_run_operation(
5447
async def my_sync_operation(
5548
self, ctx: StartOperationContext, input: MyInput
5649
) -> MyOutput:
57-
# You could use self.connected_db_client here.
5850
return MyOutput(message=f"Hello {input.name} from sync operation!")

hello_nexus/handler/worker.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from temporalio.client import Client
66
from temporalio.worker import Worker
77

8-
from hello_nexus.handler.db_client import MyDBClient
98
from hello_nexus.handler.service_handler import MyNexusServiceHandler
109
from hello_nexus.handler.workflows import WorkflowStartedByNexusOperation
1110

@@ -23,11 +22,6 @@ async def main(client: Optional[Client] = None):
2322
namespace=NAMESPACE,
2423
)
2524

26-
# Create an instance of the service handler. Your service handler class __init__ can
27-
# be written to accept any arguments that your operation handlers need when handling
28-
# requests. In this example we provide a database client object to the service hander.
29-
connected_db_client = MyDBClient.connect()
30-
3125
# Start the worker, passing the Nexus service handler instance, in addition to the
3226
# workflow classes that are started by your nexus operations, and any activities
3327
# needed. This Worker will poll for both workflow tasks and Nexus tasks (this example
@@ -36,9 +30,7 @@ async def main(client: Optional[Client] = None):
3630
client,
3731
task_queue=TASK_QUEUE,
3832
workflows=[WorkflowStartedByNexusOperation],
39-
nexus_service_handlers=[
40-
MyNexusServiceHandler(connected_db_client=connected_db_client)
41-
],
33+
nexus_service_handlers=[MyNexusServiceHandler()],
4234
):
4335
logging.info("Worker started, ctrl+c to exit")
4436
await interrupt_event.wait()

0 commit comments

Comments
 (0)