Esempio n. 1
0
def new_task(model, args):
    task = Task({'model': model, 'arguments': args, 'status': 'PENDING'})

    store.set('task:{id}'.format(id=task.id), json.dumps(task.to_primitive()))
    store.set('task:{id}:status'.format(id=task.id), task.status)
    store.lpush('task:all', task.id)

    return task
Esempio n. 2
0
def get_task(task_id):
    try:
        task_data = json.loads(store.get(store.scan_iter('task:{id}'.format(id=task_id)).next()))
        model_data = task_data.pop('model')

        task = Task(task_data)
        task.model = get_model(model_data.get('name'))
        task.status = get_task_status(task_data.get('id'))

        return task if task else None
    except StopIteration:
        return None