Skip to content

Commit

Permalink
Fix crontab scheduler -- for Sunday, datetime.isoweekday() == 7, not …
Browse files Browse the repository at this point in the history
…0, as we expect. Slight cleanup.
  • Loading branch information
berg authored and Ask Solem committed Oct 29, 2010
1 parent 3186737 commit cfb2c96
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions celery/schedules.py
Expand Up @@ -251,6 +251,9 @@ def __reduce__(self):
def remaining_estimate(self, last_run_at):
"""Returns when the periodic task should run next as a timedelta."""
weekday = last_run_at.isoweekday()
if weekday == 7: # Sunday is day 0, not day 7.
weekday = 0

execute_this_hour = (weekday in self.day_of_week and
last_run_at.hour in self.hour and
last_run_at.minute < max(self.minute))
Expand All @@ -265,8 +268,7 @@ def remaining_estimate(self, last_run_at):
next_minute = min(self.minute)

execute_today = (weekday in self.day_of_week and
(last_run_at.hour < max(self.hour) or
execute_this_hour))
last_run_at.hour < max(self.hour))

if execute_today:
next_hour = min(hour for hour in self.hour
Expand All @@ -277,13 +279,13 @@ def remaining_estimate(self, last_run_at):
microsecond=0)
else:
next_hour = min(self.hour)
iso_next_day = min([day for day in self.day_of_week
if day > weekday] or
self.day_of_week)
add_week = iso_next_day == weekday
next_day = min([day for day in self.day_of_week
if day > weekday] or
self.day_of_week)
add_week = next_day == weekday

delta = relativedelta(weeks=add_week and 1 or 0,
weekday=(iso_next_day - 1) % 7,
weekday=(next_day - 1) % 7,
hour=next_hour,
minute=next_minute,
second=0,
Expand Down

0 comments on commit cfb2c96

Please sign in to comment.