-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathclient.py
More file actions
50 lines (39 loc) · 1.69 KB
/
client.py
File metadata and controls
50 lines (39 loc) · 1.69 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
"""Client to start travel booking saga orchestrations."""
import asyncio
import json
import logging
import os
from durabletask.azuremanaged.client import DurableTaskSchedulerClient
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
logger = logging.getLogger(__name__)
async def main():
endpoint = os.getenv("ENDPOINT", "http://localhost:8080")
taskhub = os.getenv("TASKHUB", "default")
print(f"Using taskhub: {taskhub}")
print(f"Using endpoint: {endpoint}")
c = DurableTaskSchedulerClient(
host_address=endpoint,
secure_channel=endpoint != "http://localhost:8080",
taskhub=taskhub,
token_credential=None,
)
# Scenario 1: Successful booking
print("\n=== Scenario 1: Successful Booking ===")
instance_id = c.schedule_new_orchestration(
"travel_booking_saga",
input={"destination": "Paris", "nights": 5, "simulate_car_failure": False},
)
print(f"Started orchestration: {instance_id}")
result = c.wait_for_orchestration_completion(instance_id, timeout=30)
print(f"Result: {json.dumps(json.loads(result.serialized_output), indent=2)}")
# Scenario 2: Car booking fails — triggers compensation
print("\n=== Scenario 2: Car Failure + Compensation ===")
instance_id = c.schedule_new_orchestration(
"travel_booking_saga",
input={"destination": "Tokyo", "nights": 3, "simulate_car_failure": True},
)
print(f"Started orchestration: {instance_id}")
result = c.wait_for_orchestration_completion(instance_id, timeout=30)
print(f"Result: {json.dumps(json.loads(result.serialized_output), indent=2)}")
if __name__ == "__main__":
asyncio.run(main())