def test_oclock_ran_yesterday(self): self.delete() now = datetime.utcnow() if now.hour == 23: now -= timedelta(hours=1) before = now - timedelta(hours=26) datefile = Datefile('/tmp', TEST_FILE, timestamp=before) ok_(datefile.is_older_than({'oclock': now.hour})) ok_(not datefile.is_older_than({'oclock': now.hour + 1}))
def test_is_older_than(self): self.delete() before = datetime.utcnow() datefile = Datefile('/tmp', TEST_FILE) ok_(datefile.is_older_than({'seconds': 2})) ok_(datefile.is_older_than({'days': 2})) # test will stop working on Jan 1, 2170 ok_(not datefile.is_older_than({'days': 73000})) datefile.touch(before) time.sleep(3) ok_(datefile.is_older_than({'seconds': 2})) ok_(not datefile.is_older_than({'minutes': 5}))
def should_run(pid_dir, rule): if not os.path.exists(get_pid_path(pid_dir, rule)): last_run = Datefile(pid_dir, "%s.last_run" % rule.name) if last_run.is_older_than(rule.time_delta): return True else: log.debug('Skipping job: %s (last: %s)', rule.name, last_run) return False
def should_run(pid_dir, rule): last_run = Datefile(pid_dir, "%s.last_run" % rule.name) if not os.path.exists(get_pid_path(pid_dir, rule)) and \ last_run.is_older_than(rule.time_delta): return True else: log.debug('Skipping job: %s (last: %s)', rule.name, last_run) return False
def should_run(pid_dir, rule): last_run = Datefile(pid_dir, "%s.last_run" % rule.name) if not os.path.exists(get_pid_path(pid_dir, rule)): if last_run.is_older_than(rule.time_delta): return True elif rule.retry: if os.path.exists(os.path.join(pid_dir, "%s.next_retry" % rule.name)): next_retry = Datefile(pid_dir, "%s.next_retry" % rule.name) now = datetime.utcnow() if now > datetime.strptime(str(next_retry), '%Y-%m-%d %H:%M:%S'): return True log.debug('Skipping job: %s (last: %s)', rule.name, last_run) return False
def should_run(pid_dir, rule): last_run = Datefile(pid_dir, "%s.last_run" % rule.name) if not os.path.exists(get_pid_path(pid_dir, rule)): if last_run.is_older_than(rule.time_delta): return True elif rule.retry: if os.path.exists( os.path.join(pid_dir, "%s.next_retry" % rule.name)): next_retry = Datefile(pid_dir, "%s.next_retry" % rule.name) now = datetime.utcnow() if now > datetime.strptime(str(next_retry), '%Y-%m-%d %H:%M:%S'): return True log.debug('Skipping job: %s (last: %s)', rule.name, last_run) return False