-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathstarter.py
More file actions
48 lines (37 loc) · 1.16 KB
/
starter.py
File metadata and controls
48 lines (37 loc) · 1.16 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
import argparse
import asyncio
import uuid
from temporalio.client import Client
from temporalio.envconfig import ClientConfig
from worker_multiprocessing import WORKFLOW_TASK_QUEUE
from worker_multiprocessing.workflows import ParallelizedWorkflow
class Args(argparse.Namespace):
num_workflows: int
async def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"-n",
"--num-workflows",
help="the number of workflows to execute",
type=int,
default=25,
)
args = parser.parse_args(namespace=Args())
config = ClientConfig.load_client_connect_config()
config.setdefault("target_host", "localhost:7233")
client = await Client.connect(**config)
# Start several workflows
wf_handles = [
client.execute_workflow(
ParallelizedWorkflow.run,
id=f"greeting-workflow-id-{uuid.uuid4()}",
task_queue=WORKFLOW_TASK_QUEUE,
)
for _ in range(args.num_workflows)
]
# Wait for workflow completion
for wf in asyncio.as_completed(wf_handles):
result = await wf
print(result)
if __name__ == "__main__":
asyncio.run(main())