-
Notifications
You must be signed in to change notification settings - Fork 5
/
activities.py
46 lines (33 loc) · 1.33 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
from temporalio import activity
from obj import BookVacationInput
import random
@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:
seats_available = random.randint(0, 10)
try:
if seats_available < 1:
raise Exception("No seats remaining")
else:
print(f"Booking flight: {input.book_flight_id}")
except Exception:
raise Exception("No seats remaining")
@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}"