def last_run(self): self._last_run.restat(False) if not self._last_run.exists(): return CANARY_DATE with self._last_run.open('r') as in_file: date_str = in_file.read() return datetime.strptime(date_str, self._time_format).replace( tzinfo=tz.tzutc())
def last_run(self): self._last_run.restat(False) if not self._last_run.exists(): return CANARY_DATE with self._last_run.open('r') as in_file: date_str = in_file.read() return datetime.strptime(date_str, self._time_format).replace(tzinfo=tz.tzutc())
def should_run(self): current_time = datetime.utcnow().replace(tzinfo=tz.tzutc()) next_cycle = croniter(self.schedule, self.last_run).get_next(datetime) delta = (croniter(self.schedule, next_cycle).get_next(datetime) - next_cycle).total_seconds() next_cycle = next_cycle + timedelta(seconds=delta * 0.1 * self._smear_coef) if next_cycle <= current_time: return True return False
def should_run(self): current_time = datetime.utcnow().replace(tzinfo=tz.tzutc()) next_cycle = croniter(self.schedule, self.last_run).get_next(datetime) if next_cycle <= current_time: return True return False
yield self._mutex.acquire() yield self._fs_lock.deferUntilLocked() def release(self): """Release the filesystem based and in memory locks.""" self._fs_lock.unlock() self._mutex.release() @property def locked(self): return self._mutex.locked or self._fs_lock.locked # We use this date to indicate that the scheduled task has never run. # Easter egg, try to see what is special about this date :)? CANARY_DATE = datetime(1957, 10, 4, tzinfo=tz.tzutc()) class DidNotRun(Exception): pass class ScheduledTask(object): """ Two ScheduledTask instances with same identifier are not permited to run concurrently. There should be no ScheduledTask queue waiting for the lock as SchedulerService ticks quite often. """ _time_format = "%Y-%m-%dT%H:%M:%SZ" schedule = None identifier = None
def acquire(self): yield self._mutex.acquire() yield self._fs_lock.deferUntilLocked() def release(self): """Release the filesystem based and in memory locks.""" self._fs_lock.unlock() self._mutex.release() @property def locked(self): return self._mutex.locked or self._fs_lock.locked # We use this date to indicate that the scheduled task has never run. # Easter egg, try to see what is special about this date :)? CANARY_DATE = datetime(1957, 10, 4, tzinfo=tz.tzutc()) class DidNotRun(Exception): pass class ScheduledTask(object): """ Two ScheduledTask instances with same identifier are not permited to run concurrently. There should be no ScheduledTask queue waiting for the lock as SchedulerService ticks quite often. """ _time_format = "%Y-%m-%dT%H:%M:%SZ" schedule = None identifier = None