forked from temporalio/samples-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
55 lines (45 loc) · 1.57 KB
/
app.py
File metadata and controls
55 lines (45 loc) · 1.57 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 uuid
from typing import Optional
from temporalio.client import Client
from temporalio.envconfig import ClientConfig
from temporalio.worker import Worker
from nexus_multiple_args.caller.workflows import CallerWorkflow
NAMESPACE = "nexus-multiple-args-caller-namespace"
TASK_QUEUE = "nexus-multiple-args-caller-task-queue"
async def execute_caller_workflow(
client: Optional[Client] = None,
) -> tuple[str, str]:
if client is None:
config = ClientConfig.load_client_connect_config()
config.setdefault("target_host", "localhost:7233")
config.setdefault("namespace", NAMESPACE)
client = await Client.connect(**config)
async with Worker(
client,
task_queue=TASK_QUEUE,
workflows=[CallerWorkflow],
):
# Execute workflow with English language
result1 = await client.execute_workflow(
CallerWorkflow.run,
args=["Nexus", "en"],
id=str(uuid.uuid4()),
task_queue=TASK_QUEUE,
)
# Execute workflow with Spanish language
result2 = await client.execute_workflow(
CallerWorkflow.run,
args=["Nexus", "es"],
id=str(uuid.uuid4()),
task_queue=TASK_QUEUE,
)
return result1, result2
if __name__ == "__main__":
loop = asyncio.new_event_loop()
try:
results = loop.run_until_complete(execute_caller_workflow())
for result in results:
print(result)
except KeyboardInterrupt:
loop.run_until_complete(loop.shutdown_asyncgens())