Exemple #1
0
    def test_fresh(self):
        task = Task(1, 'task_id', 'name', 'job.test', {'args':(), 'kw':{}}, 'every 5')
        res = task.fresh()
        assert res == True
        assert task.task_id is None
        assert task.status == Task.SCHEDULED
        assert task.run_times == 1

        task = Task(1, 'task_id', 'name', 'job.test', {'args':(), 'kw':{}}, 'every 5')
        task.event = 'at 20141111 1212'
        res = task.fresh()
        assert res == False
Exemple #2
0
    def test_retry(self):
        task = Task(1, 'task_id', 'name', 'job.test', {'args':(), 'kw':{}}, 'every 5')
        res = task.retry()
        assert res == True
        assert task.attempts == 1
        assert task.status == Task.RETRY

        task = Task(1, 'task_id', 'name', 'job.test', {'args':(), 'kw':{}}, 'every 5')
        task.attempts = 4
        res = task.retry()
        assert res == False
        assert task.status == Task.ABORTED
        assert task.run_times == 1
Exemple #3
0
 def test_event_type(self):
     t = datetime.now() + timedelta(minutes=5)
     task = Task(1, 'task_id', 'name', 'job.test',  {'args':(), 'kw':{}}, 'at ' + t.strftime('%Y%m%d%H%M'))
     self.assertEqual(task.event_type, 'at')
     task.event = 'every 5'
     self.assertEqual(task.event_type, 'every')
Exemple #4
0
 def test_is_running(self):
     task = Task(1, 'task_id', 'name', 'job.test',  {'args':(), 'kw':{}}, '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(task.is_running(), False)
Exemple #5
0
 def test_gen_next_run(self):
     task = Task(1, 'task_id', 'name', 'job.test',  {'args':(), 'kw':{}}, '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(task.next_run, datetime.strptime("8/8/2014 16:35", "%d/%m/%Y %H:%M"))
     self.assertTrue(task.gen_next_run() > datetime.strptime("8/8/2014 16:35", "%d/%m/%Y %H:%M"))