Exemplo n.º 1
0
 def test_rerun_old_tasks(self):
     mock_datetime.set_time_override()
     try:
         task_id1 = nofail()
         task.run(task_id1)
         task_id2 = nofail()
         task.run(task_id2)
         mock_datetime.advance_time_seconds(60)
         task_id3 = nofail()
         task.run(task_id3)
         self.assertFalse(task.is_complete(task_id1))
         task.run(task_id1)
         timeout = mock_datetime.utcnow() - datetime.timedelta(seconds=30)
         num = task.timeout(timeout)
         self.assertEqual(num, 1)
         task_id = task.claim()
         self.assertEqual(task_id, task_id2)
         self.assertEqual(task.claim(), None)
         task.run(task_id)
         self.assertTrue(task.is_complete(task_id2))
         self.assertFalse(task.is_complete(task_id3))
     finally:
         mock_datetime.clear_time_override()
Exemplo n.º 2
0
 def test_rerun_old_tasks(self):
     mock_datetime.set_time_override()
     try:
         task_id1 = nofail()
         task.run(task_id1)
         task_id2 = nofail()
         task.run(task_id2)
         mock_datetime.advance_time_seconds(60)
         task_id3 = nofail()
         task.run(task_id3)
         self.assertFalse(task.is_complete(task_id1))
         task.run(task_id1)
         timeout = mock_datetime.utcnow() - datetime.timedelta(seconds=30)
         num = task.timeout(timeout)
         self.assertEqual(num, 1)
         task_id = task.claim()
         self.assertEqual(task_id, task_id2)
         self.assertEqual(task.claim(), None)
         task.run(task_id)
         self.assertTrue(task.is_complete(task_id2))
         self.assertFalse(task.is_complete(task_id3))
     finally:
         mock_datetime.clear_time_override()
Exemplo n.º 3
0
import random

import eventlet
import task

@task.ify()
def long_action(number, task_id, progress):
    tries = (progress or 0) + 1
    eventlet.sleep(random.randint(1, 10) / 10)
    if random.randint(1, 10) > 3:
        print "Action %s Failed" % number
        raise task.Failure(tries)
    print "Action %s Succeeded after %s tries" % (number, tries)
    return tries

task.setup_db('sqlite://') # in memory db

task_ids = []
for i in xrange(10):
    task_ids.append(long_action(i))

while not all(task.is_complete(task_id) for task_id in task_ids):
    task_id =  task.claim()
    if task_id:
        eventlet.spawn_n(task.run, task_id)
    eventlet.sleep(0)

for task_id in task_ids:
    print task.get(task_id)['attempts']