-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathrun_workflow.py
More file actions
40 lines (29 loc) · 1.15 KB
/
Copy pathrun_workflow.py
File metadata and controls
40 lines (29 loc) · 1.15 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
"""Start the activity interrupt workflow."""
import asyncio
import os
from temporalio.client import Client
from temporalio.contrib.strands import StrandsPlugin
from strands_plugin.activity_interrupt.workflow import ActivityInterruptWorkflow
async def main() -> None:
# The starter also goes through the plugin's failure converter so the
# Interrupt payload deserializes cleanly when the workflow result is read.
client = await Client.connect(
os.environ.get("TEMPORAL_ADDRESS", "localhost:7233"),
plugins=[StrandsPlugin()],
)
handle = await client.start_workflow(
ActivityInterruptWorkflow.run,
"Please delete the 'system' user.",
id="strands-activity-interrupt",
task_queue="strands-activity-interrupt",
)
reason = None
while reason is None:
await asyncio.sleep(0.5)
reason = await handle.query(ActivityInterruptWorkflow.pending_approval)
print(f"Approval requested: {reason}")
await handle.signal(ActivityInterruptWorkflow.approve, "approve")
result = await handle.result()
print(f"Result: {result}")
if __name__ == "__main__":
asyncio.run(main())