def test_gen_next_run(self): job = Job(1, 'job_id', 'name', 'every 5', datetime.strptime("8/8/2014 16:35", "%d/%m/%Y %H:%M"), datetime.strptime("8/8/2014 16:30", "%d/%m/%Y %H:%M")) self.assertEqual(job.next_run, datetime.strptime("8/8/2014 16:35", "%d/%m/%Y %H:%M")) self.assertTrue(job.gen_next_run() > datetime.strptime( "8/8/2014 16:35", "%d/%m/%Y %H:%M"))
def test_new(self): job = Job(1, 'job_id', 'name', 'every 5') self.assertEquals((job.name, job.event), ('name', 'every 5')) self.assertEquals(job.pattern, ['every', '5']) self.assertRaises(TypeError, lambda: Job(1, 'job_id', 'name', 'every')) self.assertRaises(TypeError, lambda: Job(1, 'job_id', 'name', 'every x')) self.assertRaises(TypeError, lambda: Job(1, 'job_id', 'name', 'at xx'))
def setUp(self): db.execute("DELETE FROM cron WHERE name like 'job%'") db.execute('INSERT INTO cron VALUES (1, NULL, %s, %s, NULL, NULL)', ('job_name1', 'every 10')) db.execute('INSERT INTO cron VALUES (2, "job_id", %s, %s, NULL, NULL)', ('job_name2', 'every 10')) self.jobthing = JobThing() self.job = Job(3, 'job_3', 'job_name3', 'every 5')
def test_event_type(self): t = datetime.now() + timedelta(minutes=5) job = Job(1, 'job_id', 'name', 'at ' + t.strftime('%Y%m%d%H%M')) self.assertEqual(job.event_type, 'at') job.event = 'every 5' self.assertEqual(job.event_type, 'every')
def _load(self, data): return Job(*data)
def setdebug(debug=False): level = logging.DEBUG if debug else logging.INFO logging.basicConfig(level=level, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') if __name__ == '__main__': setdebug(False) db.setup('localhost', 'test', 'test', 'leaf', pool_opt={ 'minconn': 3, 'maxconn': 10 }) thing_setup() next_run = datetime.now() - timedelta(minutes=10) for cron_id in range(4, 11): name = 'name_' + str(cron_id) job = Job(cron_id, None, name, event='every 2', next_run=next_run) Thing('job').save(job) time.sleep(2) try: cron = Cron(5) cron.run() except KeyboardInterrupt: exit(1)
def add_job(self, name, event): job = Job(None, None, name, event) return Thing('job').save(job)
def test_gen_next_run(self): job = Job(1, 'job_id', 'name', 'every 5', datetime.strptime("8/8/2014 16:35", "%d/%m/%Y %H:%M"), datetime.strptime("8/8/2014 16:30", "%d/%m/%Y %H:%M")) self.assertEqual(job.next_run, datetime.strptime("8/8/2014 16:35", "%d/%m/%Y %H:%M")) self.assertTrue(job.gen_next_run() > datetime.strptime("8/8/2014 16:35", "%d/%m/%Y %H:%M"))