-
-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathschedule_source.py
More file actions
59 lines (46 loc) · 2.08 KB
/
schedule_source.py
File metadata and controls
59 lines (46 loc) · 2.08 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
from typing import List
from taskiq import ScheduledTask, ScheduleSource
class MyScheduleSource(ScheduleSource):
async def startup(self) -> None:
"""Do something when starting broker."""
async def shutdown(self) -> None:
"""Do something on shutdown."""
async def get_schedules(self) -> List["ScheduledTask"]:
# Here you must return list of scheduled tasks from your source.
return [
ScheduledTask(
task_name="",
labels={},
args=[],
kwargs={},
cron="* * * * *",
),
]
# This method is optional. You may not implement this.
# It's just a helper to people to be able to interact with your source.
async def add_schedule(self, schedule: "ScheduledTask") -> None:
print("New schedule added:", schedule)
# This method is optional. You may not implement this.
# It's just a helper to people to be able to interact with your source.
async def update_schedule(self, schedule: "ScheduledTask") -> None:
print("Updating schedule:", schedule.schedule_id)
# This method is completely optional, but if you want to support
# schedule cancelation, you must implement it.
async def delete_schedule(self, schedule_id: str) -> None:
print("Deleting schedule:", schedule_id)
# This method is optional. You may not implement this.
# It's just a helper to people to be able to interact with your source.
async def pre_send(self, task: "ScheduledTask") -> 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
"""
# This method is optional. You may not implement this.
# It's just a helper to people to be able to interact with your source.
async def post_send(self, task: "ScheduledTask") -> None:
"""
Actions to execute after task was sent to broker.
:param task: task that just have sent
"""