本文整理汇总了Python中celery.worker.hub.Hub.scheduler方法的典型用法代码示例。如果您正苦于以下问题:Python Hub.scheduler方法的具体用法?Python Hub.scheduler怎么用?Python Hub.scheduler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类celery.worker.hub.Hub
的用法示例。
在下文中一共展示了Hub.scheduler方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fire_timers
# 需要导入模块: from celery.worker.hub import Hub [as 别名]
# 或者: from celery.worker.hub.Hub import scheduler [as 别名]
def test_fire_timers(self):
hub = Hub()
hub.timer = Mock()
hub.timer._queue = []
self.assertEqual(hub.fire_timers(min_delay=42.324,
max_delay=32.321), 32.321)
hub.timer._queue = [1]
hub.scheduler = iter([(3.743, None)])
self.assertEqual(hub.fire_timers(), 3.743)
e1, e2, e3 = Mock(), Mock(), Mock()
entries = [e1, e2, e3]
def se():
while 1:
while entries:
yield None, entries.pop()
yield 3.982, None
hub.scheduler = se()
self.assertEqual(hub.fire_timers(max_timers=10), 3.982)
hub.timer.apply_entry.assert_has_calls([call(x) for x in [e3, e2, e1]])
entries[:] = [Mock() for _ in range(11)]
keep = list(entries)
self.assertEqual(hub.fire_timers(max_timers=10, min_delay=1.13), 1.13)
hub.timer.apply_entry.assert_has_calls(
[call(x) for x in reversed(keep[1:])]
)
self.assertEqual(hub.fire_timers(max_timers=10), 3.982)
hub.timer.apply_entry.assert_has_calls(call(keep[0]))
示例2: test_fire_timers_raises
# 需要导入模块: from celery.worker.hub import Hub [as 别名]
# 或者: from celery.worker.hub.Hub import scheduler [as 别名]
def test_fire_timers_raises(self):
hub = Hub()
eback = Mock()
eback.side_effect = KeyError("foo")
hub.timer = Mock()
hub.scheduler = iter([(0, eback)])
with self.assertRaises(KeyError):
hub.fire_timers(propagate=(KeyError,))
eback.side_effect = ValueError("foo")
hub.scheduler = iter([(0, eback)])
with patch("celery.worker.hub.logger") as logger:
with self.assertRaises(StopIteration):
hub.fire_timers()
self.assertTrue(logger.error.called)
示例3: test_fire_timers
# 需要导入模块: from celery.worker.hub import Hub [as 别名]
# 或者: from celery.worker.hub.Hub import scheduler [as 别名]
def test_fire_timers(self):
hub = Hub()
hub.timer = Mock()
hub.timer._queue = []
self.assertEqual(hub.fire_timers(min_delay=42.324,
max_delay=32.321), 32.321)
hub.timer._queue = [1]
hub.scheduler = Mock()
hub.scheduler.next.return_value = 3.743, None
self.assertEqual(hub.fire_timers(), 3.743)
e1, e2, e3 = Mock(), Mock(), Mock()
entries = [e1, e2, e3]
def se():
if entries:
return None, entries.pop()
return 3.982, None
hub.scheduler.next = Mock()
hub.scheduler.next.side_effect = se
self.assertEqual(hub.fire_timers(max_timers=10), 3.982)
hub.timer.apply_entry.assert_has_calls(map(call, [e3, e2, e1]))
entries[:] = [Mock() for _ in xrange(11)]
keep = list(entries)
self.assertEqual(hub.fire_timers(max_timers=10, min_delay=1.13), 1.13)
hub.timer.apply_entry.assert_has_calls(
map(call, reversed(keep[1:])),
)
self.assertEqual(hub.fire_timers(max_timers=10), 3.982)
hub.timer.apply_entry.assert_has_calls(call(keep[0]))
示例4: test_fire_timers
# 需要导入模块: from celery.worker.hub import Hub [as 别名]
# 或者: from celery.worker.hub.Hub import scheduler [as 别名]
def test_fire_timers(self):
hub = Hub()
hub.timer = Mock()
hub.timer._queue = []
self.assertEqual(hub.fire_timers(min_delay=42.324, max_delay=32.321), 32.321)
hub.timer._queue = [1]
hub.scheduler = iter([(3.743, None)])
self.assertEqual(hub.fire_timers(), 3.743)
e1, e2, e3 = Mock(), Mock(), Mock()
entries = [e1, e2, e3]
reset = lambda: [m.reset() for m in [e1, e2, e3]]
def se():
while 1:
while entries:
yield None, entries.pop()
yield 3.982, None
hub.scheduler = se()
self.assertEqual(hub.fire_timers(max_timers=10), 3.982)
for E in [e3, e2, e1]:
E.assert_called_with()
reset()
entries[:] = [Mock() for _ in range(11)]
keep = list(entries)
self.assertEqual(hub.fire_timers(max_timers=10, min_delay=1.13), 1.13)
for E in reversed(keep[1:]):
E.assert_called_with()
reset()
self.assertEqual(hub.fire_timers(max_timers=10), 3.982)
keep[0].assert_called_with()
示例5: test_fire_timers
# 需要导入模块: from celery.worker.hub import Hub [as 别名]
# 或者: from celery.worker.hub.Hub import scheduler [as 别名]
def test_fire_timers(self):
hub = Hub()
hub.timer = Mock()
hub.timer._queue = []
self.assertEqual(hub.fire_timers(min_delay=42.324,
max_delay=32.321), 32.321)
hub.timer._queue = [1]
hub.scheduler = Mock()
hub.scheduler.next.return_value = 3.743, None
self.assertEqual(hub.fire_timers(), 3.743)
e1, e2, e3 = Mock(), Mock(), Mock()
entries = [e1, e2, e3]
reset = lambda: [m.reset() for m in [e1, e2, e3]]
def se():
if entries:
return None, entries.pop()
return 3.982, None
hub.scheduler.next = Mock()
hub.scheduler.next.side_effect = se
self.assertEqual(hub.fire_timers(max_timers=10), 3.982)
for E in [e3, e2, e1]:
E.assert_called_with()
reset()
entries[:] = [Mock() for _ in xrange(11)]
keep = list(entries)
self.assertEqual(hub.fire_timers(max_timers=10, min_delay=1.13), 1.13)
for E in reversed(keep[1:]):
E.assert_called_with()
reset()
self.assertEqual(hub.fire_timers(max_timers=10), 3.982)
keep[0].assert_called_with()