本文整理汇总了Python中celery.worker.listener.CarrotListener.task_consumer方法的典型用法代码示例。如果您正苦于以下问题:Python CarrotListener.task_consumer方法的具体用法?Python CarrotListener.task_consumer怎么用?Python CarrotListener.task_consumer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类celery.worker.listener.CarrotListener
的用法示例。
在下文中一共展示了CarrotListener.task_consumer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_receieve_message_eta_isoformat
# 需要导入模块: from celery.worker.listener import CarrotListener [as 别名]
# 或者: from celery.worker.listener.CarrotListener import task_consumer [as 别名]
def test_receieve_message_eta_isoformat(self):
class MockConsumer(object):
prefetch_count_incremented = False
def qos(self, **kwargs):
self.prefetch_count_incremented = True
l = CarrotListener(self.ready_queue, self.eta_schedule, self.logger,
send_events=False)
backend = MockBackend()
m = create_message(backend, task=foo_task.name,
eta=datetime.now().isoformat(),
args=[2, 4, 8], kwargs={})
l.event_dispatcher = MockEventDispatcher()
l.task_consumer = MockConsumer()
l.qos = QoS(l.task_consumer, l.initial_prefetch_count, l.logger)
l.receive_message(m.decode(), m)
items = [entry[2] for entry in self.eta_schedule.queue]
found = 0
for item in items:
if item.args[0].task_name == foo_task.name:
found = True
self.assertTrue(found)
self.assertTrue(l.task_consumer.prefetch_count_incremented)
示例2: test_mainloop
# 需要导入模块: from celery.worker.listener import CarrotListener [as 别名]
# 或者: from celery.worker.listener.CarrotListener import task_consumer [as 别名]
def test_mainloop(self):
l = CarrotListener(self.ready_queue, self.eta_schedule, self.logger,
send_events=False)
class MockConnection(object):
def drain_events(self):
return "draining"
l.connection = MockConnection()
l.connection.connection = MockConnection()
it = l._mainloop()
self.assertTrue(it.next(), "draining")
records = {}
def create_recorder(key):
def _recorder(*args, **kwargs):
records[key] = True
return _recorder
l.task_consumer = PlaceHolder()
l.task_consumer.iterconsume = create_recorder("consume_tasks")
l.broadcast_consumer = PlaceHolder()
l.broadcast_consumer.register_callback = create_recorder(
"broadcast_callback")
l.broadcast_consumer.iterconsume = create_recorder(
"consume_broadcast")
l.task_consumer.add_consumer = create_recorder("consumer_add")
records.clear()
self.assertEqual(l._detect_wait_method(), l._mainloop)
for record in ("broadcast_callback", "consume_broadcast",
"consume_tasks"):
self.assertTrue(records.get(record))
records.clear()
l.connection.connection = PlaceHolder()
self.assertIs(l._detect_wait_method(), l.task_consumer.iterconsume)
self.assertTrue(records.get("consumer_add"))