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)) if execute_this_hour: next_minute = min(minute for minute in self.minute if minute > last_run_at.minute) delta = relativedelta(minute=next_minute, second=0, microsecond=0) else: next_minute = min(self.minute) execute_today = (weekday in self.day_of_week and last_run_at.hour < max(self.hour)) if execute_today: next_hour = min(hour for hour in self.hour if hour > last_run_at.hour) delta = relativedelta(hour=next_hour, minute=next_minute, second=0, microsecond=0) else: next_hour = min(self.hour) 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=(next_day - 1) % 7, hour=next_hour, minute=next_minute, second=0, microsecond=0) return remaining(last_run_at, delta, now=self.nowfun())
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)) if execute_this_hour: next_minute = min(minute for minute in self.minute if minute > last_run_at.minute) delta = relativedelta(minute=next_minute, second=0, microsecond=0) else: next_minute = min(self.minute) execute_today = (weekday in self.day_of_week and last_run_at.hour < max(self.hour)) if execute_today: next_hour = min(hour for hour in self.hour if hour > last_run_at.hour) delta = relativedelta(hour=next_hour, minute=next_minute, second=0, microsecond=0) else: next_hour = min(self.hour) 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=(next_day - 1) % 7, hour=next_hour, minute=next_minute, second=0, microsecond=0) return remaining(last_run_at, delta, now=self.nowfun())
def test_remaining_relative(self): remaining(datetime.utcnow(), timedelta(hours=1), relative=True)
def remaining_estimate(self, last_run_at): """Returns when the periodic task should run next as a timedelta.""" return remaining(last_run_at, self.run_every, relative=self.relative)