本文整理汇总了Python中celery.worker.listener.CarrotListener.event_dispatcher方法的典型用法代码示例。如果您正苦于以下问题:Python CarrotListener.event_dispatcher方法的具体用法?Python CarrotListener.event_dispatcher怎么用?Python CarrotListener.event_dispatcher使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类celery.worker.listener.CarrotListener
的用法示例。
在下文中一共展示了CarrotListener.event_dispatcher方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_receieve_message_eta_isoformat
# 需要导入模块: from celery.worker.listener import CarrotListener [as 别名]
# 或者: from celery.worker.listener.CarrotListener import event_dispatcher [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_receive_message_control_command
# 需要导入模块: from celery.worker.listener import CarrotListener [as 别名]
# 或者: from celery.worker.listener.CarrotListener import event_dispatcher [as 别名]
def test_receive_message_control_command(self):
l = CarrotListener(self.ready_queue, self.eta_schedule, self.logger,
send_events=False)
backend = MockBackend()
m = create_message(backend, control={"command": "shutdown"})
l.event_dispatcher = MockEventDispatcher()
l.control_dispatch = MockControlDispatch()
l.receive_message(m.decode(), m)
self.assertIn("shutdown", l.control_dispatch.commands)
示例3: test_receieve_message_not_registered
# 需要导入模块: from celery.worker.listener import CarrotListener [as 别名]
# 或者: from celery.worker.listener.CarrotListener import event_dispatcher [as 别名]
def test_receieve_message_not_registered(self):
l = CarrotListener(self.ready_queue, self.eta_schedule, self.logger,
send_events=False)
backend = MockBackend()
m = create_message(backend, task="x.X.31x", args=[2, 4, 8], kwargs={})
l.event_dispatcher = MockEventDispatcher()
self.assertFalse(l.receive_message(m.decode(), m))
self.assertRaises(Empty, self.ready_queue.get_nowait)
self.assertTrue(self.eta_schedule.empty())
示例4: test_receive_message_InvalidTaskError
# 需要导入模块: from celery.worker.listener import CarrotListener [as 别名]
# 或者: from celery.worker.listener.CarrotListener import event_dispatcher [as 别名]
def test_receive_message_InvalidTaskError(self):
logger = MockLogger()
l = CarrotListener(self.ready_queue, self.eta_schedule, logger,
send_events=False)
backend = MockBackend()
m = create_message(backend, task=foo_task.name,
args=(1, 2), kwargs="foobarbaz", id=1)
l.event_dispatcher = MockEventDispatcher()
l.control_dispatch = MockControlDispatch()
l.receive_message(m.decode(), m)
self.assertIn("Invalid task ignored", logger.logged[0])
示例5: test_receive_message_unknown
# 需要导入模块: from celery.worker.listener import CarrotListener [as 别名]
# 或者: from celery.worker.listener.CarrotListener import event_dispatcher [as 别名]
def test_receive_message_unknown(self):
l = CarrotListener(self.ready_queue, self.eta_schedule, self.logger,
send_events=False)
backend = MockBackend()
m = create_message(backend, unknown={"baz": "!!!"})
l.event_dispatcher = MockEventDispatcher()
l.control_dispatch = MockControlDispatch()
import warnings
with warnings.catch_warnings(record=True) as log:
l.receive_message(m.decode(), m)
self.assertTrue(log)
self.assertTrue("unknown message" in log[0].message.args[0])
示例6: test_receieve_message
# 需要导入模块: from celery.worker.listener import CarrotListener [as 别名]
# 或者: from celery.worker.listener.CarrotListener import event_dispatcher [as 别名]
def test_receieve_message(self):
l = CarrotListener(self.ready_queue, self.eta_schedule, self.logger,
send_events=False)
backend = MockBackend()
m = create_message(backend, task=foo_task.name,
args=[2, 4, 8], kwargs={})
l.event_dispatcher = MockEventDispatcher()
l.receive_message(m.decode(), m)
in_bucket = self.ready_queue.get_nowait()
self.assertIsInstance(in_bucket, TaskRequest)
self.assertEqual(in_bucket.task_name, foo_task.name)
self.assertEqual(in_bucket.execute(), 2 * 4 * 8)
self.assertTrue(self.eta_schedule.empty())
示例7: test_revoke
# 需要导入模块: from celery.worker.listener import CarrotListener [as 别名]
# 或者: from celery.worker.listener.CarrotListener import event_dispatcher [as 别名]
def test_revoke(self):
ready_queue = FastQueue()
l = CarrotListener(ready_queue, self.eta_schedule, self.logger,
send_events=False)
backend = MockBackend()
id = gen_unique_id()
c = create_message(backend, control={"command": "revoke",
"task_id": id})
t = create_message(backend, task=foo_task.name, args=[2, 4, 8],
kwargs={}, id=id)
l.event_dispatcher = MockEventDispatcher()
l.receive_message(c.decode(), c)
from celery.worker.state import revoked
self.assertIn(id, revoked)
l.receive_message(t.decode(), t)
self.assertTrue(ready_queue.empty())
示例8: test_receieve_message_eta_isoformat
# 需要导入模块: from celery.worker.listener import CarrotListener [as 别名]
# 或者: from celery.worker.listener.CarrotListener import event_dispatcher [as 别名]
def test_receieve_message_eta_isoformat(self):
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.receive_message(m.decode(), m)
items = [entry[2] for entry in self.eta_schedule.queue]
found = 0
for item in items:
if item.task_name == foo_task.name:
found = True
self.assertTrue(found)