|
| 1 | +import asyncio |
| 2 | +import logging |
| 3 | +from typing import Optional |
| 4 | + |
| 5 | +from temporalio.client import Client |
| 6 | +from temporalio.worker import Worker |
| 7 | + |
| 8 | +from nexus_multiple_args.handler.service_handler import MyNexusServiceHandler |
| 9 | +from nexus_multiple_args.handler.workflows import HelloHandlerWorkflow |
| 10 | + |
| 11 | +interrupt_event = asyncio.Event() |
| 12 | + |
| 13 | +NAMESPACE = "nexus-multiple-args-handler-namespace" |
| 14 | +TASK_QUEUE = "nexus-multiple-args-handler-task-queue" |
| 15 | + |
| 16 | + |
| 17 | +async def main(client: Optional[Client] = None): |
| 18 | + logging.basicConfig(level=logging.INFO) |
| 19 | + |
| 20 | + client = client or await Client.connect( |
| 21 | + "localhost:7233", |
| 22 | + namespace=NAMESPACE, |
| 23 | + ) |
| 24 | + |
| 25 | + # Start the worker, passing the Nexus service handler instance, in addition to the |
| 26 | + # workflow classes that are started by your nexus operations, and any activities |
| 27 | + # needed. This Worker will poll for both workflow tasks and Nexus tasks. |
| 28 | + async with Worker( |
| 29 | + client, |
| 30 | + task_queue=TASK_QUEUE, |
| 31 | + workflows=[HelloHandlerWorkflow], |
| 32 | + nexus_service_handlers=[MyNexusServiceHandler()], |
| 33 | + ): |
| 34 | + logging.info("Worker started, ctrl+c to exit") |
| 35 | + await interrupt_event.wait() |
| 36 | + logging.info("Shutting down") |
| 37 | + |
| 38 | + |
| 39 | +if __name__ == "__main__": |
| 40 | + loop = asyncio.new_event_loop() |
| 41 | + try: |
| 42 | + loop.run_until_complete(main()) |
| 43 | + except KeyboardInterrupt: |
| 44 | + interrupt_event.set() |
| 45 | + loop.run_until_complete(loop.shutdown_asyncgens()) |
0 commit comments