-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_starter.py
More file actions
55 lines (40 loc) · 1.39 KB
/
_starter.py
File metadata and controls
55 lines (40 loc) · 1.39 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
44
45
46
47
48
49
50
51
52
53
54
55
import asyncio
import concurrent
from temporalio.client import Client
from temporalio.common import WorkflowIDReusePolicy
from temporalio.converter import (
DataConverter,
)
from temporalio.worker import Worker
from activity import compose_greeting
from codec import EncryptionCodec
from converter import PydanticPayloadConverter
from test_types import ComposeGreetingRequest
from workflow import GreetingWorkflow
async def main():
# Start client
client = await Client.connect(
"localhost:7233",
data_converter=DataConverter(
payload_converter_class=PydanticPayloadConverter,
payload_codec=EncryptionCodec()
)
)
tasks= []
for i in range(200):
tasks.append(asyncio.create_task(start_workflow(client, i)))
await asyncio.gather(*tasks)
async def start_workflow(client, i):
workflowId = "hello-activity-workflow-id-" + str(i)
await client.execute_workflow(
GreetingWorkflow.run,
ComposeGreetingRequest(id=str(i), name="World"),
id=workflowId,
task_queue="hello-activity-task-queue",
# for this example I want to terminate workflows with the same id so they start new every time
# we run the script
id_conflict_policy=WorkflowIDReusePolicy.TERMINATE_IF_RUNNING
)
print(f"completed workflow id : {workflowId}")
if __name__ == "__main__":
asyncio.run(main())