示例#1
0
def task_remove(action, action_id):

    key_name = Task.key_from(action=action, action_id=action_id)

    q = Task.get_by_key_name(key_name)
    if not q:
        raise exceptions.ApiTaskDoesntExist

    q.delete()

    return True
示例#2
0
def task_get(action, action_id, expire=settings.DEFAULT_TASK_EXPIRE):

    key_name = Task.key_from(action=action, action_id=action_id)

    def _attempt_lock(key, expire):
        qi = db.get(key)
        now = datetime.utcnow()
        if qi.expire and qi.expire > now:
            raise exceptions.ApiTaskExpired
        qi.expire = now + timedelta(seconds=expire)
        qi.put()

    qu = Task.get_by_key_name(key_name)
    if not qu:
        raise exceptions.ApiMethodUnavailable

    try:
        db.run_in_transaction(_attempt_lock, qu.key(), expire)
        return Task.get_by_key_name(key_name)
    except db.TransactionFailedError:
        raise exceptions.ApiLockError

    return qu