Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/examples/extending/schedule_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ async def get_schedules(self) -> List["ScheduledTask"]:
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just call delete and create in this method? Isn't it enough? Why do we need a separate method in each result_backend?

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:
Expand Down
23 changes: 23 additions & 0 deletions taskiq/abc/schedule_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,29 @@ async def add_schedule(
f"The source {self.__class__.__name__} does not support adding schedules.",
)

async def update_schedule(
self,
schedule: "ScheduledTask",
) -> None:
"""
Update an existing schedule.

This function is used to update existing schedules.
It's a convenient helper for people who want to update schedules
for the current source.

As an example, if your source works with a database,
you may want to update existing rows in the table.

Note that this function may do nothing.

:param schedule: schedule to update.
"""
raise NotImplementedError(
f"The source {self.__class__.__name__} does "
"not support updating schedules.",
)

async def delete_schedule(self, schedule_id: str) -> None:
"""
Method to delete schedule by id.
Expand Down