Repository navigation
Expand file tree
/
Copy pathschedule_source.py
More file actions
77 lines (58 loc) · 2.2 KB
/
Copy pathschedule_source.py
File metadata and controls
77 lines (58 loc) · 2.2 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Any, Coroutine, List, Union
if TYPE_CHECKING: # pragma: no cover
from taskiq.scheduler.scheduled_task import ScheduledTask
class ScheduleSource(ABC):
"""Abstract class for source of scheduled tasks."""
async def startup(self) -> None: # noqa: B027
"""Action to execute during startup."""
async def shutdown(self) -> None: # noqa: B027
"""Actions to execute during shutdown."""
@abstractmethod
async def get_schedules(self) -> List["ScheduledTask"]:
"""Get list of taskiq schedules."""
async def add_schedule(
self,
schedule: "ScheduledTask",
) -> None:
"""
Add a new schedule.
This function is used to add new schedules.
It's a convenient helper for people who want to add new schedules
for the current source.
As an example, if your source works with a database,
you may want to add new rows to the table.
Note that this function may do nothing.
:param schedule: schedule to add.
"""
raise NotImplementedError(
f"The source {self.__class__.__name__} does not support adding schedules.",
)
async def delete_schedule(self, schedule_id: str) -> None:
"""
Method to delete schedule by id.
This is useful for schedule cancelation.
:param schedule_id: id of schedule to delete.
"""
raise NotImplementedError(
f"The source {self.__class__.__name__} does "
"not support deleting schedules.",
)
def pre_send( # noqa: B027
self,
task: "ScheduledTask",
) -> Union[None, Coroutine[Any, Any, None]]:
"""
Actions to execute before task will be sent to broker.
This method may raise ScheduledTaskCancelledError.
This cancels the task execution.
:param task: task that will be sent
"""
def post_send( # noqa: B027
self,
task: "ScheduledTask",
) -> Union[None, Coroutine[Any, Any, None]]:
"""
Actions to execute after task was sent to broker.
:param task: task that just have sent
"""