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


Python Hub.timer方法代码示例

本文整理汇总了Python中celery.worker.hub.Hub.timer方法的典型用法代码示例。如果您正苦于以下问题:Python Hub.timer方法的具体用法?Python Hub.timer怎么用?Python Hub.timer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在celery.worker.hub.Hub的用法示例。


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

示例1: test_fire_timers

# 需要导入模块: from celery.worker.hub import Hub [as 别名]
# 或者: from celery.worker.hub.Hub import timer [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]))
开发者ID:DotNetWebs,项目名称:celery,代码行数:34,代码来源:test_hub.py

示例2: test_fire_timers

# 需要导入模块: from celery.worker.hub import Hub [as 别名]
# 或者: from celery.worker.hub.Hub import timer [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]))
开发者ID:Acidburn0zzz,项目名称:firefox-flicks,代码行数:35,代码来源:test_hub.py

示例3: test_fire_timers_raises

# 需要导入模块: from celery.worker.hub import Hub [as 别名]
# 或者: from celery.worker.hub.Hub import timer [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)
开发者ID:ryandub,项目名称:celery,代码行数:17,代码来源:test_hub.py

示例4: test_fire_timers

# 需要导入模块: from celery.worker.hub import Hub [as 别名]
# 或者: from celery.worker.hub.Hub import timer [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()
开发者ID:DHLabs,项目名称:keep_isn,代码行数:39,代码来源:test_hub.py

示例5: test_fire_timers

# 需要导入模块: from celery.worker.hub import Hub [as 别名]
# 或者: from celery.worker.hub.Hub import timer [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()
开发者ID:rfkrocktk,项目名称:celery,代码行数:38,代码来源:test_hub.py


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