forked from temporalio/samples-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.py
More file actions
43 lines (34 loc) · 1.2 KB
/
worker.py
File metadata and controls
43 lines (34 loc) · 1.2 KB
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
34
35
36
37
38
39
40
41
42
43
import asyncio
from temporalio.client import Client
from temporalio.envconfig import ClientConfig
from temporalio.worker import Worker
from custom_converter.shared import greeting_data_converter
from custom_converter.workflow import GreetingWorkflow
interrupt_event = asyncio.Event()
async def main():
config = ClientConfig.load_client_connect_config()
config.setdefault("target_host", "localhost:7233")
# Connect client
client = await Client.connect(
**config,
# Without this, when trying to run a workflow, we get:
# KeyError: 'Unknown payload encoding my-greeting-encoding
data_converter=greeting_data_converter,
)
# Run a worker for the workflow
async with Worker(
client,
task_queue="custom_converter-task-queue",
workflows=[GreetingWorkflow],
):
# 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())