-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflows.py
50 lines (39 loc) · 1.21 KB
/
workflows.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
from datetime import timedelta
from temporalio import workflow
from activities import Database
db_instance = Database()
@workflow.defn
class AddTaskWorkflow:
@workflow.run
async def add_task(self, title: str) -> list:
return await workflow.execute_activity(
db_instance.add_task,
title,
start_to_close_timeout=timedelta(seconds=10),
)
@workflow.defn
class GetAllTasksWorkflow:
@workflow.run
async def get_all_tasks(self) -> list:
return await workflow.execute_activity(
db_instance.get_all_tasks,
start_to_close_timeout=timedelta(seconds=10),
)
@workflow.defn
class GetTaskWorkflow:
@workflow.run
async def get_task_by_id(self, task_id: int) -> dict:
return await workflow.execute_activity(
db_instance.get_task_by_id,
task_id,
start_to_close_timeout=timedelta(seconds=10),
)
@workflow.defn
class ToggleTaskWorkflow:
@workflow.run
async def toggle_task(self, task_id: int) -> dict:
return await workflow.execute_activity(
db_instance.toggle_task,
task_id,
start_to_close_timeout=timedelta(seconds=10),
)