forked from temporalio/samples-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello_update.py
54 lines (42 loc) · 1.5 KB
/
hello_update.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import asyncio
from temporalio import workflow
from temporalio.client import Client
from temporalio.worker import Worker
@workflow.defn
class GreetingWorkflow:
def __init__(self):
self.is_complete = False
@workflow.run
async def run(self) -> str:
await workflow.wait_condition(lambda: self.is_complete)
return "Hello, World!"
@workflow.update
async def update_workflow_status(self) -> str:
self.is_complete = True
return "Workflow status updated"
async def main():
client = await Client.connect("localhost:7233")
# Run a worker for the workflow
async with Worker(
client,
task_queue="update-workflow-task-queue",
workflows=[GreetingWorkflow],
):
# While the worker is running, use the client to start the workflow.
# Note, in many production setups, the client would be in a completely
# separate process from the worker.
handle = await client.start_workflow(
GreetingWorkflow.run,
id="hello-update-workflow-id",
task_queue="update-workflow-task-queue",
)
# Perform the update for GreetingWorkflow
update_result = await handle.execute_update(
GreetingWorkflow.update_workflow_status
)
print(f"Update Result: {update_result}")
# Get the result for GreetingWorkflow
result = await handle.result()
print(f"Workflow Result: {result}")
if __name__ == "__main__":
asyncio.run(main())