-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.py
33 lines (29 loc) · 1.14 KB
/
worker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import asyncio
from datetime import timedelta
from temporalio.worker import Worker
from modules.temporal import get_temporal_client
from modules.workflows.player import PlayerWorkflow, create_auth
from modules.workflows.round import RoundWorkflow, create_customers, create_uuid, post_to_client, do_client_handshake
interrupt_event = asyncio.Event()
async def main():
# Connect client
temporal_client = await get_temporal_client()
# Run a worker for the workflow
async with Worker(
temporal_client,
task_queue="background-check-queue",
workflows=[PlayerWorkflow, RoundWorkflow],
activities=[create_auth, create_uuid, create_customers, do_client_handshake, post_to_client],
graceful_shutdown_timeout=timedelta(seconds=0.5)
):
# Wait until interrupted
print("Worker started, ctrl+c to exit")
await interrupt_event.wait()
print("Shutting down")
if __name__ == "__main__":
loop = asyncio.new_event_loop()
try:
loop.run_until_complete(main())
except KeyboardInterrupt:
interrupt_event.set()
loop.run_until_complete(loop.shutdown_asyncgens())