-
Notifications
You must be signed in to change notification settings - Fork 5
/
activities.py
53 lines (38 loc) · 1.46 KB
/
activities.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
import asyncio
from dataclasses import dataclass
from temporalio import activity
@dataclass
class BookVacationInput:
book_user_id: str
book_car_id: str
book_hotel_id: str
book_flight_id: str
@activity.defn
async def book_car(input: BookVacationInput) -> str:
print(f"Booking car: {input.book_car_id}")
return f"Booked car: {input.book_car_id}"
@activity.defn
async def book_hotel(input: BookVacationInput) -> str:
print(f"Booking hotel: {input.book_hotel_id}")
return f"Booked hotel: {input.book_hotel_id}"
@activity.defn
async def book_flight(input: BookVacationInput) -> str:
if activity.info().attempt < 4:
activity.heartbeat(
f"Invoking activity, attempt number {activity.info().attempt}"
)
await asyncio.sleep(1)
raise RuntimeError("Service is down")
return f"Booking flight: {input.book_flight_id}"
@activity.defn
async def undo_book_car(input: BookVacationInput) -> str:
print(f"Undoing booking of car: {input.book_car_id}")
return f"Undoing booking of car: {input.book_car_id}"
@activity.defn
async def undo_book_hotel(input: BookVacationInput) -> str:
print(f"Undoing booking of hotel: {input.book_hotel_id}")
return f"Undoing booking of hotel: {input.book_hotel_id}"
@activity.defn
async def undo_book_flight(input: BookVacationInput) -> str:
print(f"Undoing booking of flight: {input.book_flight_id}")
return f"Undoing booking of flight: {input.book_flight_id}"