예제 #1
0
    if progress['phase'] < 1:
        progress['phase'] += 1
        yield progress
    if progress['phase'] < 2:
        if random.randint(1, 10) > 5:
            raise task.Failure(progress)
        progress['phase'] += 1
        yield progress
    if progress['phase'] < 3:
        if random.randint(1, 10) > 1:
            raise task.Failure(progress)
        progress['phase'] += 1
        yield progress


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


def get_results(results):
    try:
        for progress in results:
            print "Phase %s Complete" % progress['phase']
    except task.Failure as ex:
        print "Phase %s Failed" % (ex.progress['phase'] + 1)


while not task.is_complete(task_id):
    results = task.run(task_id)
    get_results(results)
예제 #2
0
 def setUp(self):
     task.setup_db('sqlite://')
     task.inject_now_method(mock_datetime.utcnow)
     super(TaskTestCase, self).setUp()
예제 #3
0
 def setUp(self):
     task.setup_db('sqlite://')
     task.inject_now_method(mock_datetime.utcnow)
     super(TaskTestCase, self).setUp()
예제 #4
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']