예제 #1
0
 def test_touch(self):
     datefile = Datefile('/tmp', TEST_FILE)
     actual = datefile.timestamp
     after = datetime.utcnow()
     datefile.touch()
     ok_(datefile.timestamp > actual)
     ok_(actual < after)
예제 #2
0
파일: test_pid.py 프로젝트: pooya/inferno
    def test_should_run(self):
        # without last run file

        eq_(pid.should_run(self.pid_dir, self.job.rule), True)

        print 'hee --> %s %s' % (self.pid_dir,self.job.rule_name)

        self._make_temp_pid_file()
        # with last run file that's new
        d = Datefile(self.pid_dir, "%s.last_run" % self.job.rule_name,
                 timestamp=datetime.utcnow())
        print 'yo --> %s' % d.timestamp
        eq_(pid.should_run(self.pid_dir, self.job.rule), False)

        # with last run file that's old
        Datefile(self.pid_dir, "%s.last_run" % self.job.rule_name,
            timestamp=Datefile.EPOCH)
        eq_(pid.should_run(self.pid_dir, self.job.rule), False)

        os.remove('%s/%s.pid' % (self.pid_dir, self.job.rule_name))

        # right date, with no pid
        Datefile(self.pid_dir, "%s.last_run" % self.job.rule_name,
                 timestamp=Datefile.EPOCH)
        eq_(pid.should_run(self.pid_dir, self.job.rule), True)
예제 #3
0
파일: pid.py 프로젝트: pooya/inferno
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
예제 #4
0
파일: pid.py 프로젝트: 0scarLi/inferno
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
예제 #5
0
 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}))
예제 #6
0
파일: pid.py 프로젝트: chango/inferno
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
예제 #7
0
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
예제 #8
0
 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}))
예제 #9
0
def create_next_retry(pid_dir, rule):
    # we should retry this rule in rule.retry_delay number of hours
    from datetime import timedelta
    Datefile(pid_dir,
             "%s.next_retry" % rule.name,
             timestamp=datetime.utcnow() +
             timedelta(0, 0, 0, 0, 0, int(rule.retry_delay), 0))
예제 #10
0
 def test_creation(self):
     # ensure newly created Datefiles are 'old'
     self.delete()
     after = datetime.utcnow()
     datefile = Datefile('/tmp', TEST_FILE)
     actual = datefile.timestamp
     ok_(after > actual)
     ok_(os.path.exists(os.path.join('/tmp', TEST_FILE)))
예제 #11
0
def create_failed(pid_dir, rule):
    Datefile(pid_dir, "%s.failed" % rule.name, timestamp=datetime.utcnow())
    next_retry = os.path.join(pid_dir, "%s.next_retry" % rule.name)
    if os.path.exists(next_retry):
        os.unlink(next_retry)
예제 #12
0
def create_last_run(pid_dir, rule):
    Datefile(pid_dir, "%s.last_run" % rule.name, timestamp=datetime.utcnow())
예제 #13
0
 def test_reopening(self):
     # test overriding the timestamp
     before = datetime.utcnow()
     datefile = Datefile('/tmp', TEST_FILE, timestamp=datetime.utcnow())
     actual = datefile.timestamp
     ok_(before < actual)