-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathstarter.py
More file actions
36 lines (27 loc) · 1.13 KB
/
starter.py
File metadata and controls
36 lines (27 loc) · 1.13 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
import asyncio
from temporalio.client import Client
from temporalio.envconfig import ClientConfig
from custom_decorator.worker import WaitForCancelWorkflow
async def main():
# Connect client
config = ClientConfig.load_client_connect_config()
config.setdefault("target_host", "localhost:7233")
client = await Client.connect(**config)
# Start the workflow
handle = await client.start_workflow(
WaitForCancelWorkflow.run,
id=f"custom_decorator-workflow-id",
task_queue="custom_decorator-task-queue",
)
print("Started workflow, waiting 5 seconds before cancelling")
await asyncio.sleep(5)
# Send a signal asking workflow to cancel the activity
await handle.signal(WaitForCancelWorkflow.cancel_activity)
# Wait and expect to be told about the activity being cancelled. If we did
# not have the automatic heartbeater decorator, the signal would have failed
# because the workflow would already be completed as failed with activity
# heartbeat timeout.
result = await handle.result()
print(f"Result: {result}")
if __name__ == "__main__":
asyncio.run(main())