当前位置: 首页>>代码示例>>Python>>正文


Python consumer.Consumer类代码示例

本文整理汇总了Python中celery.worker.consumer.Consumer的典型用法代码示例。如果您正苦于以下问题:Python Consumer类的具体用法?Python Consumer怎么用?Python Consumer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Consumer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_on_task_no_events

 def test_on_task_no_events(self):
     l = MainConsumer(self.ready_queue, self.eta_schedule, send_events=False)
     task = Mock()
     task.revoked.return_value = False
     l.event_dispatcher = Mock()
     l.event_dispatcher.enabled = False
     task.eta = None
     l._does_info = False
     l.on_task(task)
开发者ID:iancmcc,项目名称:celery,代码行数:9,代码来源:test_worker.py

示例2: test_on_task_no_events

 def test_on_task_no_events(self):
     l = Consumer(self.ready_queue, timer=self.timer)
     task = Mock()
     task.revoked.return_value = False
     l.event_dispatcher = Mock()
     l.event_dispatcher.enabled = False
     task.eta = None
     l._does_info = False
     l.on_task(task)
开发者ID:julienp,项目名称:celery,代码行数:9,代码来源:test_worker.py

示例3: test_on_decode_error

    def test_on_decode_error(self, crit):
        l = Consumer(self.ready_queue, timer=self.timer)

        class MockMessage(Mock):
            content_type = 'application/x-msgpack'
            content_encoding = 'binary'
            body = 'foobarbaz'

        message = MockMessage()
        l.on_decode_error(message, KeyError('foo'))
        self.assertTrue(message.ack.call_count)
        self.assertIn("Can't decode message body", crit.call_args[0][0])
开发者ID:julienp,项目名称:celery,代码行数:12,代码来源:test_worker.py

示例4: test_receieve_message

    def test_receieve_message(self):
        l = Consumer(self.ready_queue, timer=self.timer)
        m = create_message(Mock(), task=foo_task.name,
                           args=[2, 4, 8], kwargs={})
        l.update_strategies()
        callback = self._get_on_message(l)
        callback(m.decode(), m)

        in_bucket = self.ready_queue.get_nowait()
        self.assertIsInstance(in_bucket, Request)
        self.assertEqual(in_bucket.name, foo_task.name)
        self.assertEqual(in_bucket.execute(), 2 * 4 * 8)
        self.assertTrue(self.timer.empty())
开发者ID:julienp,项目名称:celery,代码行数:13,代码来源:test_worker.py

示例5: LoopConsumer

 def LoopConsumer(self, buffer=None, controller=None, timer=None, app=None,
                  without_mingle=True, without_gossip=True,
                  without_heartbeat=True, **kwargs):
     if controller is None:
         controller = Mock(name='.controller')
     buffer = buffer if buffer is not None else self.buffer.put
     timer = timer if timer is not None else self.timer
     app = app if app is not None else self.app
     c = Consumer(
         buffer,
         timer=timer,
         app=app,
         controller=controller,
         without_mingle=without_mingle,
         without_gossip=without_gossip,
         without_heartbeat=without_heartbeat,
         **kwargs
     )
     c.task_consumer = Mock(name='.task_consumer')
     c.qos = QoS(c.task_consumer.qos, 10)
     c.connection = Mock(name='.connection')
     c.controller = c.app.WorkController()
     c.heart = Mock(name='.heart')
     c.controller.consumer = c
     c.pool = c.controller.pool = Mock(name='.controller.pool')
     c.node = Mock(name='.node')
     c.event_dispatcher = mock_event_dispatcher()
     return c
开发者ID:auvipy,项目名称:celery,代码行数:28,代码来源:test_worker.py

示例6: get_consumer

 def get_consumer(self, no_hub=False, **kwargs):
     consumer = Consumer(
         on_task_request=Mock(),
         init_callback=Mock(),
         pool=Mock(),
         app=self.app,
         timer=Mock(),
         controller=Mock(),
         hub=None if no_hub else Mock(),
         **kwargs
     )
     consumer.blueprint = Mock()
     consumer._restart_state = Mock()
     consumer.connection = Mock()
     consumer.connection_errors = (socket.error, OSError, )
     return consumer
开发者ID:OnShift,项目名称:celery,代码行数:16,代码来源:test_consumer.py

示例7: __init__

 def __init__(self, app, heartbeat=None, on_task=None):
     (
         self.obj,
         self.connection,
         self.consumer,
         self.blueprint,
         self.hub,
         self.qos,
         self.heartbeat,
         self.clock,
     ) = self.args = [Mock(name='obj'),
                      Mock(name='connection'),
                      Mock(name='consumer'),
                      Mock(name='blueprint'),
                      Mock(name='Hub'),
                      Mock(name='qos'),
                      heartbeat,
                      Mock(name='clock')]
     self.connection.supports_heartbeats = True
     self.consumer.callbacks = []
     self.obj.strategies = {}
     self.connection.connection_errors = (socket.error, )
     #hent = self.Hub.__enter__ = Mock(name='Hub.__enter__')
     #self.Hub.__exit__ = Mock(name='Hub.__exit__')
     #self.hub = hent.return_value = Mock(name='hub_context')
     self.hub.on_task = on_task or []
     self.hub.readers = {}
     self.hub.writers = {}
     self.hub.consolidate = set()
     self.hub.fire_timers.return_value = 1.7
     self.Hub = self.hub
     # need this for create_task_handler
     _consumer = Consumer(Mock(), timer=Mock(), app=app)
     self.obj.create_task_handler = _consumer.create_task_handler
     self.on_unknown_message = self.obj.on_unknown_message = Mock(
         name='on_unknown_message',
     )
     _consumer.on_unknown_message = self.on_unknown_message
     self.on_unknown_task = self.obj.on_unknown_task = Mock(
         name='on_unknown_task',
     )
     _consumer.on_unknown_task = self.on_unknown_task
     self.on_invalid_task = self.obj.on_invalid_task = Mock(
         name='on_invalid_task',
     )
     _consumer.on_invalid_task = self.on_invalid_task
     _consumer.strategies = self.obj.strategies
开发者ID:dn0,项目名称:celery,代码行数:47,代码来源:test_loops.py

示例8: test_receieve_message_ack_raises

    def test_receieve_message_ack_raises(self, logger, warn):
        l = Consumer(self.ready_queue, timer=self.timer)
        backend = Mock()
        m = create_message(backend, args=[2, 4, 8], kwargs={})

        l.event_dispatcher = Mock()
        l.connection_errors = (socket.error, )
        m.reject = Mock()
        m.reject.side_effect = socket.error('foo')
        callback = self._get_on_message(l)
        self.assertFalse(callback(m.decode(), m))
        self.assertTrue(warn.call_count)
        with self.assertRaises(Empty):
            self.ready_queue.get_nowait()
        self.assertTrue(self.timer.empty())
        m.reject.assert_called_with()
        self.assertTrue(logger.critical.call_count)
开发者ID:julienp,项目名称:celery,代码行数:17,代码来源:test_worker.py

示例9: test_loop

    def test_loop(self):

        class Connection(current_app.connection().__class__):
            obj = None

            def drain_events(self, **kwargs):
                self.obj.connection = None

        l = Consumer(self.ready_queue, timer=self.timer)
        l.connection = Connection()
        l.connection.obj = l
        l.task_consumer = Mock()
        l.qos = QoS(l.task_consumer, 10)

        l.loop(*l.loop_args())
        l.loop(*l.loop_args())
        self.assertTrue(l.task_consumer.consume.call_count)
        l.task_consumer.qos.assert_called_with(prefetch_count=10)
        l.task_consumer.qos = Mock()
        self.assertEqual(l.qos.value, 10)
        l.qos.decrement_eventually()
        self.assertEqual(l.qos.value, 9)
        l.qos.update()
        self.assertEqual(l.qos.value, 9)
        l.task_consumer.qos.assert_called_with(prefetch_count=9)
开发者ID:julienp,项目名称:celery,代码行数:25,代码来源:test_worker.py

示例10: test_loop_when_socket_error

    def test_loop_when_socket_error(self):

        class Connection(current_app.connection().__class__):
            obj = None

            def drain_events(self, **kwargs):
                self.obj.connection = None
                raise socket.error('foo')

        l = Consumer(self.ready_queue, timer=self.timer)
        l.namespace.state = RUN
        c = l.connection = Connection()
        l.connection.obj = l
        l.task_consumer = Mock()
        l.qos = QoS(l.task_consumer, 10)
        with self.assertRaises(socket.error):
            l.loop(*l.loop_args())

        l.namespace.state = CLOSE
        l.connection = c
        l.loop(*l.loop_args())
开发者ID:julienp,项目名称:celery,代码行数:21,代码来源:test_worker.py

示例11: __init__

 def __init__(self, app, heartbeat=None, on_task_message=None,
              transport_driver_type=None):
     hub = Hub()
     (
         self.obj,
         self.connection,
         self.consumer,
         self.blueprint,
         self.hub,
         self.qos,
         self.heartbeat,
         self.clock,
     ) = self.args = [Mock(name='obj'),
                      Mock(name='connection'),
                      Mock(name='consumer'),
                      Mock(name='blueprint'),
                      hub,
                      Mock(name='qos'),
                      heartbeat,
                      Mock(name='clock')]
     self.connection.supports_heartbeats = True
     self.connection.get_heartbeat_interval.side_effect = (
         lambda: self.heartbeat
     )
     self.consumer.callbacks = []
     self.obj.strategies = {}
     self.connection.connection_errors = (socket.error,)
     if transport_driver_type:
         self.connection.transport.driver_type = transport_driver_type
     self.hub.readers = {}
     self.hub.writers = {}
     self.hub.consolidate = set()
     self.hub.timer = Mock(name='hub.timer')
     self.hub.timer._queue = [Mock()]
     self.hub.fire_timers = Mock(name='hub.fire_timers')
     self.hub.fire_timers.return_value = 1.7
     self.hub.poller = Mock(name='hub.poller')
     self.hub.close = Mock(name='hub.close()')  # asynloop calls hub.close
     self.Hub = self.hub
     self.blueprint.state = RUN
     # need this for create_task_handler
     _consumer = Consumer(Mock(), timer=Mock(), app=app)
     _consumer.on_task_message = on_task_message or []
     self.obj.create_task_handler = _consumer.create_task_handler
     self.on_unknown_message = self.obj.on_unknown_message = Mock(
         name='on_unknown_message',
     )
     _consumer.on_unknown_message = self.on_unknown_message
     self.on_unknown_task = self.obj.on_unknown_task = Mock(
         name='on_unknown_task',
     )
     _consumer.on_unknown_task = self.on_unknown_task
     self.on_invalid_task = self.obj.on_invalid_task = Mock(
         name='on_invalid_task',
     )
     _consumer.on_invalid_task = self.on_invalid_task
     _consumer.strategies = self.obj.strategies
开发者ID:aidan,项目名称:celery,代码行数:57,代码来源:test_loops.py

示例12: __init__

 def __init__(self, app, heartbeat=None, on_task_message=None):
     hub = Hub()
     (
         self.obj,
         self.connection,
         self.consumer,
         self.blueprint,
         self.hub,
         self.qos,
         self.heartbeat,
         self.clock,
     ) = self.args = [
         Mock(name="obj"),
         Mock(name="connection"),
         Mock(name="consumer"),
         Mock(name="blueprint"),
         hub,
         Mock(name="qos"),
         heartbeat,
         Mock(name="clock"),
     ]
     self.connection.supports_heartbeats = True
     self.connection.get_heartbeat_interval.side_effect = lambda: self.heartbeat
     self.consumer.callbacks = []
     self.obj.strategies = {}
     self.connection.connection_errors = (socket.error,)
     self.hub.readers = {}
     self.hub.writers = {}
     self.hub.consolidate = set()
     self.hub.timer = Mock(name="hub.timer")
     self.hub.timer._queue = [Mock()]
     self.hub.fire_timers = Mock(name="hub.fire_timers")
     self.hub.fire_timers.return_value = 1.7
     self.hub.poller = Mock(name="hub.poller")
     self.hub.close = Mock(name="hub.close()")  # asynloop calls hub.close
     self.Hub = self.hub
     self.blueprint.state = RUN
     # need this for create_task_handler
     _consumer = Consumer(Mock(), timer=Mock(), app=app)
     _consumer.on_task_message = on_task_message or []
     self.obj.create_task_handler = _consumer.create_task_handler
     self.on_unknown_message = self.obj.on_unknown_message = Mock(name="on_unknown_message")
     _consumer.on_unknown_message = self.on_unknown_message
     self.on_unknown_task = self.obj.on_unknown_task = Mock(name="on_unknown_task")
     _consumer.on_unknown_task = self.on_unknown_task
     self.on_invalid_task = self.obj.on_invalid_task = Mock(name="on_invalid_task")
     _consumer.on_invalid_task = self.on_invalid_task
     _consumer.strategies = self.obj.strategies
开发者ID:punitx,项目名称:celery,代码行数:48,代码来源:test_loops.py

示例13: test_on_task_revoked

 def test_on_task_revoked(self):
     l = Consumer(self.ready_queue, timer=self.timer)
     task = Mock()
     task.revoked.return_value = True
     l.on_task(task)
开发者ID:julienp,项目名称:celery,代码行数:5,代码来源:test_worker.py

示例14: test_reset_connection_with_no_node

    def test_reset_connection_with_no_node(self):

        l = MainConsumer(self.ready_queue, self.eta_schedule, self.logger)
        self.assertEqual(None, l.pool)
        l.reset_connection()
开发者ID:alessandrod,项目名称:celery,代码行数:5,代码来源:__init__.py

示例15: T

import sys

@task(accept_magic_kwargs=False)
def T():
    pass

tid = uuid()
P = TaskPool()
hostname = socket.gethostname()
task = {'task': T.name, 'args': (), 'kwargs': {}, 'id': tid, 'flags': 0}
app = current_app._get_current_object()
ready_queue = Queue()

def on_put(req):
    req.execute_using_pool(P)

def on_ack(*a): pass


m = Message(None, {}, {}, task)

ready_queue.put = on_put
x = Consumer(ready_queue, hostname=hostname, app=app)
x.update_strategies()
name = T.name
ts = time()
for i in range(100000):
    x.strategies[name](m, m.body, on_ack)
print(time() - ts)

开发者ID:Dalar,项目名称:celery,代码行数:29,代码来源:req.py


注:本文中的celery.worker.consumer.Consumer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。