Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow IntervalSchedule to use a custom schedule type. #697

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions django_celery_beat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ class IntervalSchedule(models.Model):
>>> every=2, period=DAYS
"""

_schedule_cls_ = schedules.schedule

DAYS = DAYS
HOURS = HOURS
MINUTES = MINUTES
Expand Down Expand Up @@ -176,7 +178,7 @@ class Meta:

@property
def schedule(self):
return schedules.schedule(
return self._schedule_cls_(
timedelta(**{self.period: self.every}),
nowfun=lambda: make_aware(now())
)
Expand All @@ -185,7 +187,9 @@ def schedule(self):
def from_schedule(cls, schedule, period=SECONDS):
every = max(schedule.run_every.total_seconds(), 0)
try:
return cls.objects.get(every=every, period=period)
obj = cls.objects.get(every=every, period=period)
obj._schedule_cls_ = type(schedule)
return obj
except cls.DoesNotExist:
return cls(every=every, period=period)
except MultipleObjectsReturned:
Expand Down