def is_due(self): try: if not self.uniformly_scheduled and not isinstance( self.schedule, crontab): run_in = self.run_at - time.time() if run_in > 0: value = schedstate(is_due=False, next=run_in) else: value = schedstate(is_due=True, next=self.schedule.seconds) else: value = super(PanoptesScheduleEntry, self).is_due() except Exception as e: # If there is an issue with the key set in redis # Assume 60 second Interval. print(f'{self.name} Attribute Error {repr(e)}') self.run_at = time.time() + 60 value = schedstate(is_due=False, next=60) if value[0] and self.kv_store: # This `ScheduleEntry` is due to be executed. # Update the `last_uniformly_scheduled` key in Redis uniformly_scheduled = time.time() last_uniformly_scheduled_at_key = ':'.join( ['plugin_metadata', self.name, 'last_uniformly_scheduled']) self.kv_store.set(last_uniformly_scheduled_at_key, str(uniformly_scheduled), expire=int(self.schedule.seconds * 2)) return value
def is_due(self): if not self.model.enabled: # 5 second delay for re-enable. return schedules.schedstate(False, 5.0) # START DATE: only run after the `start_time`, if one exists. if self.model.start_time is not None: now = self._default_now() if getattr(settings, 'DJANGO_CELERY_BEAT_TZ_AWARE', True): now = maybe_make_aware(self._default_now()) if now < self.model.start_time: # The datetime is before the start date - don't run. # send a delay to retry on start_time delay = math.ceil( (self.model.start_time - now).total_seconds()) return schedules.schedstate(False, delay) # ONE OFF TASK: Disable one off tasks after they've ran once if self.model.one_off and self.model.enabled \ and self.model.total_run_count > 0: self.model.enabled = False self.model.total_run_count = 0 # Reset self.model.no_changes = False # Mark the model entry as changed self.model.save() # Don't recheck return schedules.schedstate(False, NEVER_CHECK_TIMEOUT) # CAUTION: make_aware assumes settings.TIME_ZONE for naive datetimes, # while maybe_make_aware assumes utc for naive datetimes tz = self.app.timezone last_run_at_in_tz = maybe_make_aware(self.last_run_at).astimezone(tz) return self.schedule.is_due(last_run_at_in_tz)
def is_due(self): if not self.model.enabled: # 5 second delay for re-enable. return schedules.schedstate(False, 5.0) # START DATE: only run after the `start_time`, if one exists. if self.model.start_time is not None: now = maybe_make_aware(self._default_now()) start_time = self.model.start_time.replace( tzinfo=self.app.timezone) if now < start_time: # The datetime is before the start date - don't run. _, delay = self.schedule.is_due(self.last_run_at) # use original delay for re-check return schedules.schedstate(False, delay) # ONE OFF TASK: Disable one off tasks after they've ran once if self.model.one_off and self.model.enabled \ and self.model.total_run_count > 0: self.model.enabled = False # disable self.model.total_run_count = 0 # Reset self.model.no_changes = False # Mark the model entry as changed save_fields = ('enabled', ) # the additional fields to save self.save(save_fields) return schedules.schedstate(False, None) # Don't recheck return self.schedule.is_due(self.last_run_at)
def is_due(self): if not self.model.enabled: # 5 second delay for re-enable. return schedules.schedstate(False, 5.0) # START DATE: only run after the `start_time`, if one exists. if self.model.start_time is not None: now = maybe_make_aware(self._default_now()) if now < self.model.start_time: # The datetime is before the start date - don't run. # send a delay to retry on start_time delay = math.ceil( (self.model.start_time - now).total_seconds()) return schedules.schedstate(False, delay) # ONE OFF TASK: Disable one off tasks after they've ran once if self.model.one_off and self.model.enabled \ and self.model.total_run_count > 0: self.model.enabled = False self.model.total_run_count = 0 # Reset self.model.no_changes = False # Mark the model entry as changed self.model.save() return schedules.schedstate(False, None) # Don't recheck return self.schedule.is_due(self.last_run_at)
def is_due(self, last_run_at): if not self.enabled: return schedstate(is_due=False, next=None) rem_delta = self.remaining_estimate(None) remaining_s = max(rem_delta.total_seconds(), 0) if remaining_s == 0: if self.model: # self.model.enabled = False self.model.save() return schedstate(is_due=True, next=None) return schedstate(is_due=False, next=remaining_s)
def is_due(self): if not self.model.enabled: return schedules.schedstate(False, 5.0) # 5 second delay for re-enable. if self.model.start_time is not None: now = self._default_now() if now < self.model.start_time: delay = math.ceil( (self.model.start_time - now).total_seconds()) return schedules.schedstate(False, delay) return self.schedule.is_due(self.last_run_at)
def is_due(self): if not self.model.enabled: # 5 second delay for re-enable. return schedules.schedstate(False, 5.0) # START DATE: only run after the `start_time`, if one exists. if self.model.start_time is not None: now = self._default_now() if getattr(settings, 'DJANGO_CELERY_BEAT_TZ_AWARE', True): now = maybe_make_aware(self._default_now()) if now < self.model.start_time: # The datetime is before the start date - don't run. # send a delay to retry on start_time delay = math.ceil( (self.model.start_time - now).total_seconds()) return schedules.schedstate(False, delay) # ONE OFF TASK: Disable one off tasks after they've ran once if self.model.one_off and self.model.enabled \ and self.model.total_run_count > 0: self.model.enabled = False self.model.total_run_count = 0 # Reset self.model.no_changes = False # Mark the model entry as changed self.model.save() return schedules.schedstate(False, None) # Don't recheck # When Django settings USE_TZ is False and Django settings TIME_ZONE is set # value of TIME_ZINE is the time zone in which Django will store all datetimes. # Because of that if datetime is naive we should use it as source timezone # celery.utils.time.maybe_make_aware - always convert naive datetime to UTC # which may be wrong in Django sicase. django_timezone = getattr(settings, 'TIME_ZONE', None) django_use_tz = getattr(settings, 'USE_TZ', None) if (not django_use_tz and django_timezone and self.last_run_at.tzinfo is None and self.app.timezone): source_timezone = pytz.timezone(django_timezone) last_run_at_django_tz = source_timezone.localize(self.last_run_at) self.last_run_at = last_run_at_django_tz.astimezone( self.app.timezone) # CAUTION: make_aware assumes settings.TIME_ZONE for naive datetimes, # while maybe_make_aware assumes utc for naive datetimes tz = self.app.timezone last_run_at_in_tz = maybe_make_aware(self.last_run_at).astimezone(tz) return self.schedule.is_due(last_run_at_in_tz)
def is_due(self): if not self._task.enabled: return schedules.schedstate(False, 5.0) # 5 second delay for re-enable. if hasattr(self._task, 'start_after') and self._task.start_after: if datetime.datetime.now() < self._task.start_after: return schedules.schedstate(False, 5.0) if hasattr(self._task, 'max_run_count') and self._task.max_run_count: if (self._task.total_run_count or 0) >= self._task.max_run_count: self._task.enabled = False self._task.save() # Don't recheck return schedules.schedstate(False, None) if self._task.run_immediately: # figure out when the schedule would run next anyway _, n = self.schedule.is_due(self.last_run_at) return True, n return self.schedule.is_due(self.last_run_at)
def is_due(self): start_after = self._task.get('start_after', None) if start_after is not None: now = self.default_now() start_time = to_date(start_after) if now < start_time: delay = math.ceil((start_time - now).total_seconds()) return celery_schedules.schedstate(False, delay) max_run_count = self._task.get('max_run_count', -1) if max_run_count > 0 and self.total_run_count >= max_run_count: return celery_schedules.schedstate(False, None) run_immediately = self._task.get(RUN_IMMEDIATELY_KEY, False) if run_immediately: result = self.schedule.is_due(self.last_run_at) return celery_schedules.schedstate(True, result.next) result = self.schedule.is_due(self.last_run_at) return result
def is_due(self): if not self.model.enabled: # 5 second delay for re-enable. return schedules.schedstate(False, 5.0) # START DATE: only run after the `start_time`, if one exists. if self.model.start_time is not None: if maybe_make_aware(self._default_now()) < self.model.start_time: # The datetime is before the start date - don't run. _, delay = self.schedule.is_due(self.last_run_at) # use original delay for re-check return schedules.schedstate(False, delay) # ONE OFF TASK: Disable one off tasks after they've ran once if self.model.one_off and self.model.enabled \ and self.model.total_run_count > 0: self.model.enabled = False self.model.total_run_count = 0 # Reset self.model.no_changes = False # Mark the model entry as changed self.model.save() return schedules.schedstate(False, None) # Don't recheck return self.schedule.is_due(self.last_run_at)
def is_due(self, last_run_at): return schedstate(False, None)
def is_due(self, last_run_at): rem_delta = self.remaining_estimate(None) remaining_s = max(rem_delta.total_seconds(), 0) if remaining_s == 0: return schedules.schedstate(is_due=True, next=NEVER_CHECK_TIMEOUT) return schedules.schedstate(is_due=False, next=remaining_s)
def is_due(self): if not self._task.enabled: return schedules.schedstate(False, 5.0) # 5 second delay for re-enable. return self.schedule.is_due(self.last_run_at)