Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(12)  |  Call(10)  |  Derive(0)  |  Import(2)

        def start_filter(app, conn, filter, limit=None, timeout=1.0,
                 ack_messages=False, tasks=None, queues=None,
                 callback=None, forever=False, on_declare_queue=None,
                 consume_from=None, state=None, accept=None, **kwargs):
    state = state or State()
    queues = prepare_queues(queues)
    consume_from = [_maybe_queue(app, q)
                    for q in consume_from or list(queues)]
    if isinstance(tasks, string_t):
        tasks = set(tasks.split(','))
    if tasks is None:
        tasks = set([])

    def update_state(body, message):
        state.count += 1
        if limit and state.count >= limit:
            raise StopFiltering()

    def ack_message(body, message):
        message.ack()

    consumer = app.amqp.TaskConsumer(conn, queues=consume_from, accept=accept)

    if tasks:
        filter = filter_callback(filter, tasks)
        update_state = filter_callback(update_state, tasks)
        ack_message = filter_callback(ack_message, tasks)

    consumer.register_callback(filter)
    consumer.register_callback(update_state)
    if ack_messages:
        consumer.register_callback(ack_message)
    if callback is not None:
        callback = partial(callback, state)
        if tasks:
            callback = filter_callback(callback, tasks)
        consumer.register_callback(callback)

    # declare all queues on the new broker.
    for queue in consumer.queues:
        if queues and queue.name not in queues:
            continue
        if on_declare_queue is not None:
            on_declare_queue(queue)
        try:
            _, mcount, _ = queue(consumer.channel).queue_declare(passive=True)
            if mcount:
                state.total_apx += mcount
        except conn.channel_errors:
            pass

    # start migrating messages.
    with consumer:
        try:
            for _ in eventloop(conn,  # pragma: no cover
                               timeout=timeout, ignore_timeouts=forever):
                pass
        except socket.timeout:
            pass
        except StopFiltering:
            pass
    return state
        


src/c/e/celery-3.1.11/celery/tests/contrib/test_migrate.py   celery(Download)
from kombu.transport.virtual import QoS
 
from celery.contrib.migrate import (
    StopFiltering,
    State,
            consumer.register_callback = register_callback
 
            start_filter(app, conn, filt,
                         queues='foo,bar', ack_messages=True)
            body = {'task': 'add', 'id': 'id'}
            for callback in consumer.callbacks:
                callback(body, Message(body))
            consumer.callbacks[:] = []
            cb = Mock(name='callback=')
            start_filter(app, conn, filt, tasks='add,mul', callback=cb)
 
            on_declare_queue = Mock()
            start_filter(app, conn, filt, tasks='add,mul', queues='foo',
                         on_declare_queue=on_declare_queue)
            self.assertTrue(on_declare_queue.called)
            start_filter(app, conn, filt, queues=['foo', 'bar'])

src/c/e/celery-HEAD/celery/tests/contrib/test_migrate.py   celery(Download)
from kombu.transport.virtual import QoS
 
from celery.contrib.migrate import (
    StopFiltering,
    State,
            consumer.register_callback = register_callback
 
            start_filter(app, conn, filt,
                         queues='foo,bar', ack_messages=True)
            body = {'task': 'add', 'id': 'id'}
            for callback in consumer.callbacks:
                callback(body, Message(body))
            consumer.callbacks[:] = []
            cb = Mock(name='callback=')
            start_filter(app, conn, filt, tasks='add,mul', callback=cb)
 
            on_declare_queue = Mock()
            start_filter(app, conn, filt, tasks='add,mul', queues='foo',
                         on_declare_queue=on_declare_queue)
            self.assertTrue(on_declare_queue.called)
            start_filter(app, conn, filt, queues=['foo', 'bar'])