예제 #1
0
def async_creation_runner(cache, somekey, creator, mutex):
    """ Used by dogpile.core:Lock when appropriate.

    Instead of directly computing the value, this instead adds a task to
    a redis queue with instructions for a worker on how to import and
    invoke function that we want.

    It also assumes the cache is backed by memcached and so provides the
    worker both with the cache key for the new value as well as the
    memcached key for the distributed mutex (so it can be released later).
    """

    # Re-use those artificial attributes that we stuck on the cached fns
    fn = dict(path=creator._path, type=creator._type, name=creator._name)
    freevar_dict = dict(zip(
        creator.func_code.co_freevars,
        [c.cell_contents for c in (creator.func_closure or [])]
    ))
    task = retask.task.Task(json.dumps(dict(
        fn=fn,
        kw=freevar_dict['kw'],
        mutex_key=mutex.key,
        cache_key=somekey,
    )))
    # fire-and-forget
    queue.enqueue(task)
예제 #2
0
파일: __init__.py 프로젝트: pep8bot/pep8bot
def webhook(request):
    """ Handle github webhook. """

    # TODO -- check X-Hub-Signature

    salt = "TODO MAKE THIS SECRET"

    if 'payload' in request.params:
        payload = request.params['payload']
        if isinstance(payload, basestring):
            payload = json.loads(payload)

        queue = retask.queue.Queue('commits')
        task = retask.task.Task(payload)
        queue.connect()

        # Fire and forget
        job = queue.enqueue(task)
    else:
        raise NotImplementedError()

    return "OK"