-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_worker.py
49 lines (40 loc) · 1.4 KB
/
run_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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import asyncio
import os
from typing import Optional
from temporalio.client import Client, TLSConfig
from temporalio.worker import Worker
# Import the activity and workflow from our other files
from activities import greet
from workflows import VersioningExample
async def main():
if os.getenv("TEMPORAL_MTLS_TLS_CERT") and os.getenv("TEMPORAL_MTLS_TLS_KEY"):
server_root_ca_cert: Optional[bytes] = None
with open(os.getenv("TEMPORAL_MTLS_TLS_CERT"), "rb") as f:
client_cert = f.read()
with open(os.getenv("TEMPORAL_MTLS_TLS_KEY"), "rb") as f:
client_key = f.read()
# Start client
client = await Client.connect(
os.getenv("TEMPORAL_HOST_URL"),
namespace=os.getenv("TEMPORAL_NAMESPACE"),
tls=TLSConfig(
server_root_ca_cert=server_root_ca_cert,
client_cert=client_cert,
client_private_key=client_key,
),
)
else:
client = await Client.connect("localhost:7233")
versioning_build_id = os.getenv("VERSIONING_BUILD_ID")
# Run the worker
worker = Worker(
client,
task_queue="versioned-queue",
workflows=[VersioningExample],
activities=[greet],
build_id=f"{versioning_build_id}",
use_worker_versioning=True,
)
await worker.run()
if __name__ == "__main__":
asyncio.run(main())