Esempio n. 1
0
async def main_loop():
    """
    Fetch, forever
    """
    connection = rabbitmq.get_connection()
    connection.declare_queue_consume(rabbitmq.Fetch, NFetchers,
                                     rabbitmq.acking_callback(handle_fetch))
    # Run forever
    await connection._closed_event.wait()
Esempio n. 2
0
async def main_loop():
    """
    Run fetchers and renderers, forever.
    """
    async with PgRenderLocker() as pg_render_locker:

        @rabbitmq.manual_acking_callback
        async def render_callback(message, ack):
            return await handle_render(message, ack, pg_render_locker)

        connection = rabbitmq.get_connection()
        connection.declare_queue_consume(rabbitmq.Render, render_callback)
        # Run forever
        await connection._closed_event.wait()
Esempio n. 3
0
async def get_connection():
    """
    Ensure rabbitmq is initialized.

    This is pretty janky.
    """
    ret = rabbitmq.get_connection()

    # Now, ret is returned but ret.connect() hasn't been called -- meaning we
    # can't call any other functions on it.
    #
    # Tell asyncio to start that `.connect()` (which has already been
    # scheduled)  _before_ doing anything else. sleep(0) does the trick.
    await asyncio.sleep(0)

    return ret
Esempio n. 4
0
async def main_loop():
    """
    Run fetchers and renderers, forever.
    """
    async with PgLocker() as pg_locker:

        @rabbitmq.acking_callback_with_requeue
        async def render_callback(*args, **kwargs):
            return await handle_render(pg_locker, *args, **kwargs)

        connection = rabbitmq.get_connection()

        connection.declare_queue_consume(rabbitmq.Render, NRenderers,
                                         render_callback)
        connection.declare_queue_consume(
            rabbitmq.Fetch, NFetchers, rabbitmq.acking_callback(handle_fetch))

        # Run forever
        while True:
            await asyncio.sleep(99999)
Esempio n. 5
0
async def _queue_render(workflow_id, delta_id):
    # a separate function for dependency injection
    connection = rabbitmq.get_connection()
    await connection.queue_render(workflow_id, delta_id)