-
Notifications
You must be signed in to change notification settings - Fork 57
/
activity_worker.py
37 lines (28 loc) · 1008 Bytes
/
activity_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
import asyncio
import random
import string
from temporalio import activity
from temporalio.client import Client
from temporalio.worker import Worker
task_queue = "say-hello-task-queue"
workflow_name = "say-hello-workflow"
activity_name = "say-hello-activity"
@activity.defn(name=activity_name)
async def say_hello_activity(name: str) -> str:
return f"Hello, {name}!"
async def main():
# Create client to localhost on default namespace
client = await Client.connect("localhost:7233")
# Run activity worker
async with Worker(client, task_queue=task_queue, activities=[say_hello_activity]):
# Run the Go workflow
workflow_id = "".join(
random.choices(string.ascii_uppercase + string.digits, k=30)
)
result = await client.execute_workflow(
workflow_name, "Temporal", id=workflow_id, task_queue=task_queue
)
# Print out "Hello, Temporal!"
print(result)
if __name__ == "__main__":
asyncio.run(main())