forked from temporalio/samples-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
45 lines (35 loc) · 1.35 KB
/
run.py
File metadata and controls
45 lines (35 loc) · 1.35 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
import asyncio
import uuid
from temporalio.client import Client
from temporalio.envconfig import ClientConfig
from temporalio.worker import Worker
from eager_wf_start.activities import greeting
from eager_wf_start.workflows import EagerWorkflow
TASK_QUEUE = "eager-wf-start-task-queue"
async def main():
# Note that the worker and client run in the same process and share the same client connection.
config = ClientConfig.load_client_connect_config()
config.setdefault("target_host", "localhost:7233")
client = await Client.connect(**config)
worker = Worker(
client,
task_queue=TASK_QUEUE,
workflows=[EagerWorkflow],
activities=[greeting],
)
# Run worker in the background
async with worker:
# Start workflow(s) while worker is running
wf_handle = await client.start_workflow(
EagerWorkflow.run,
"Temporal",
id=f"eager-workflow-id-{uuid.uuid4()}",
task_queue=TASK_QUEUE,
request_eager_start=True,
)
# This is an internal flag not intended to be used publicly.
# It is used here purely to display that the workflow was eagerly started.
print(f"Workflow eagerly started: {wf_handle.__temporal_eagerly_started}")
print(await wf_handle.result())
if __name__ == "__main__":
asyncio.run(main())