當前位置: 首頁>>代碼示例>>Python>>正文


Python periodic_task.PeriodicTasks方法代碼示例

本文整理匯總了Python中oslo_service.periodic_task.PeriodicTasks方法的典型用法代碼示例。如果您正苦於以下問題:Python periodic_task.PeriodicTasks方法的具體用法?Python periodic_task.PeriodicTasks怎麽用?Python periodic_task.PeriodicTasks使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在oslo_service.periodic_task的用法示例。


在下文中一共展示了periodic_task.PeriodicTasks方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from oslo_service import periodic_task [as 別名]
# 或者: from oslo_service.periodic_task import PeriodicTasks [as 別名]
def __init__(self):
        super(KuryrK8sService, self).__init__()
        periodic_task.PeriodicTasks.__init__(self, CONF)

        objects.register_locally_defined_vifs()
        pipeline = h_pipeline.ControllerPipeline(self.tg)
        self.watcher = watcher.Watcher(pipeline, self.tg)
        self.health_manager = health.HealthServer()
        self.current_leader = None
        self.node_name = utils.get_node_name()

        handlers = _load_kuryr_ctrlr_handlers()
        for handler in handlers:
            self.watcher.add(handler.get_watch_path())
            pipeline.register(handler)
        self.pool_driver = drivers.VIFPoolDriver.get_instance(
            specific_driver='multi_pool')
        self.pool_driver.set_vif_driver() 
開發者ID:openstack,項目名稱:kuryr-kubernetes,代碼行數:20,代碼來源:service.py

示例2: test_called_correct

# 需要導入模塊: from oslo_service import periodic_task [as 別名]
# 或者: from oslo_service.periodic_task import PeriodicTasks [as 別名]
def test_called_correct(self, mock_now):

        time = 360444
        mock_now.return_value = time

        test_spacing = 9

        # Class inside test def to mock 'now' in
        # the periodic task decorator
        class AService(periodic_task.PeriodicTasks):
            def __init__(self, conf):
                super(AService, self).__init__(conf)
                self.called = {'ticks': 0}

            @periodic_task.periodic_task(spacing=test_spacing)
            def tick(self, context):
                self.called['ticks'] += 1

        serv = AService(self.conf)
        for i in range(200):
            serv.run_periodic_tasks(None)
            self.assertEqual(int(i / test_spacing), serv.called['ticks'])
            time += 1
            mock_now.return_value = time 
開發者ID:openstack,項目名稱:oslo.service,代碼行數:26,代碼來源:test_periodic.py

示例3: test_raises

# 需要導入模塊: from oslo_service import periodic_task [as 別名]
# 或者: from oslo_service.periodic_task import PeriodicTasks [as 別名]
def test_raises(self, mock_now):
        time = 230000
        mock_now.return_value = time

        class AService(periodic_task.PeriodicTasks):
            def __init__(self, conf):
                super(AService, self).__init__(conf)
                self.called = {'urg': 0, }

            @periodic_task.periodic_task
            def crashit(self, context):
                self.called['urg'] += 1
                raise AnException('urg')

        serv = AService(self.conf)
        now = serv._periodic_last_run['crashit']

        mock_now.return_value = now + periodic_task.DEFAULT_INTERVAL
        self.assertRaises(AnException,
                          serv.run_periodic_tasks,
                          None, raise_on_error=True) 
開發者ID:openstack,項目名稱:oslo.service,代碼行數:23,代碼來源:test_periodic.py

示例4: test_name

# 需要導入模塊: from oslo_service import periodic_task [as 別名]
# 或者: from oslo_service.periodic_task import PeriodicTasks [as 別名]
def test_name(self):
        class AService(periodic_task.PeriodicTasks):
            def __init__(self, conf):
                super(AService, self).__init__(conf)

            @periodic_task.periodic_task(name='better-name')
            def tick(self, context):
                pass

            @periodic_task.periodic_task
            def tack(self, context):
                pass

        @periodic_task.periodic_task(name='another-name')
        def foo(self, context):
            pass

        serv = AService(self.conf)
        serv.add_periodic_task(foo)
        self.assertIn('better-name', serv._periodic_last_run)
        self.assertIn('another-name', serv._periodic_last_run)
        self.assertIn('tack', serv._periodic_last_run) 
開發者ID:openstack,項目名稱:oslo.service,代碼行數:24,代碼來源:test_periodic.py

示例5: __init__

# 需要導入模塊: from oslo_service import periodic_task [as 別名]
# 或者: from oslo_service.periodic_task import PeriodicTasks [as 別名]
def __init__(self):
        super(PeriodicTasks, self).__init__(CONF) 
開發者ID:openstack,項目名稱:manila,代碼行數:4,代碼來源:manager.py

示例6: test_meta

# 需要導入模塊: from oslo_service import periodic_task [as 別名]
# 或者: from oslo_service.periodic_task import PeriodicTasks [as 別名]
def test_meta(self):
        class Manager(periodic_task.PeriodicTasks):

            @periodic_task.periodic_task
            def foo(self):
                return 'foo'

            @periodic_task.periodic_task(spacing=4)
            def bar(self):
                return 'bar'

            @periodic_task.periodic_task(enabled=False)
            def baz(self):
                return 'baz'

        m = Manager(self.conf)
        self.assertThat(m._periodic_tasks, matchers.HasLength(2))
        self.assertEqual(periodic_task.DEFAULT_INTERVAL,
                         m._periodic_spacing['foo'])
        self.assertEqual(4, m._periodic_spacing['bar'])
        self.assertThat(
            m._periodic_spacing, matchers.Not(matchers.Contains('baz')))

        @periodic_task.periodic_task
        def external():
            return 42

        m.add_periodic_task(external)
        self.assertThat(m._periodic_tasks, matchers.HasLength(3))
        self.assertEqual(periodic_task.DEFAULT_INTERVAL,
                         m._periodic_spacing['external']) 
開發者ID:openstack,項目名稱:oslo.service,代碼行數:33,代碼來源:test_periodic.py

示例7: test_periodic_tasks_with_idle

# 需要導入模塊: from oslo_service import periodic_task [as 別名]
# 或者: from oslo_service.periodic_task import PeriodicTasks [as 別名]
def test_periodic_tasks_with_idle(self):
        class Manager(periodic_task.PeriodicTasks):

            @periodic_task.periodic_task(spacing=200)
            def bar(self):
                return 'bar'

        m = Manager(self.conf)
        self.assertThat(m._periodic_tasks, matchers.HasLength(1))
        self.assertEqual(200, m._periodic_spacing['bar'])

        # Now a single pass of the periodic tasks
        idle = m.run_periodic_tasks(None)
        self.assertAlmostEqual(60, idle, 1) 
開發者ID:openstack,項目名稱:oslo.service,代碼行數:16,代碼來源:test_periodic.py

示例8: test_periodic_tasks_idle_calculation

# 需要導入模塊: from oslo_service import periodic_task [as 別名]
# 或者: from oslo_service.periodic_task import PeriodicTasks [as 別名]
def test_periodic_tasks_idle_calculation(self, mock_now):
        fake_time = 32503680000.0
        mock_now.return_value = fake_time

        class Manager(periodic_task.PeriodicTasks):

            @periodic_task.periodic_task(spacing=10)
            def bar(self, context):
                return 'bar'

        m = Manager(self.conf)

        # Ensure initial values are correct
        self.assertEqual(1, len(m._periodic_tasks))
        task_name, task = m._periodic_tasks[0]

        # Test task values
        self.assertEqual('bar', task_name)
        self.assertEqual(10, task._periodic_spacing)
        self.assertTrue(task._periodic_enabled)
        self.assertFalse(task._periodic_external_ok)
        self.assertFalse(task._periodic_immediate)
        self.assertAlmostEqual(32503680000.0,
                               task._periodic_last_run)

        # Test the manager's representation of those values
        self.assertEqual(10, m._periodic_spacing[task_name])
        self.assertAlmostEqual(32503680000.0,
                               m._periodic_last_run[task_name])

        mock_now.return_value = fake_time + 5
        idle = m.run_periodic_tasks(None)
        self.assertAlmostEqual(5, idle, 1)
        self.assertAlmostEqual(32503680000.0,
                               m._periodic_last_run[task_name])

        mock_now.return_value = fake_time + 10
        idle = m.run_periodic_tasks(None)
        self.assertAlmostEqual(10, idle, 1)
        self.assertAlmostEqual(32503680010.0,
                               m._periodic_last_run[task_name]) 
開發者ID:openstack,項目名稱:oslo.service,代碼行數:43,代碼來源:test_periodic.py

示例9: test_periodic_tasks_immediate_runs_now

# 需要導入模塊: from oslo_service import periodic_task [as 別名]
# 或者: from oslo_service.periodic_task import PeriodicTasks [as 別名]
def test_periodic_tasks_immediate_runs_now(self, mock_now):
        fake_time = 32503680000.0
        mock_now.return_value = fake_time

        class Manager(periodic_task.PeriodicTasks):

            @periodic_task.periodic_task(spacing=10, run_immediately=True)
            def bar(self, context):
                return 'bar'

        m = Manager(self.conf)

        # Ensure initial values are correct
        self.assertEqual(1, len(m._periodic_tasks))
        task_name, task = m._periodic_tasks[0]

        # Test task values
        self.assertEqual('bar', task_name)
        self.assertEqual(10, task._periodic_spacing)
        self.assertTrue(task._periodic_enabled)
        self.assertFalse(task._periodic_external_ok)
        self.assertTrue(task._periodic_immediate)
        self.assertIsNone(task._periodic_last_run)

        # Test the manager's representation of those values
        self.assertEqual(10, m._periodic_spacing[task_name])
        self.assertIsNone(m._periodic_last_run[task_name])

        idle = m.run_periodic_tasks(None)
        self.assertAlmostEqual(32503680000.0,
                               m._periodic_last_run[task_name])
        self.assertAlmostEqual(10, idle, 1)

        mock_now.return_value = fake_time + 5
        idle = m.run_periodic_tasks(None)
        self.assertAlmostEqual(5, idle, 1) 
開發者ID:openstack,項目名稱:oslo.service,代碼行數:38,代碼來源:test_periodic.py

示例10: test_periodic_tasks_disabled

# 需要導入模塊: from oslo_service import periodic_task [as 別名]
# 或者: from oslo_service.periodic_task import PeriodicTasks [as 別名]
def test_periodic_tasks_disabled(self):
        class Manager(periodic_task.PeriodicTasks):

            @periodic_task.periodic_task(spacing=-1)
            def bar(self):
                return 'bar'

        m = Manager(self.conf)
        idle = m.run_periodic_tasks(None)
        self.assertAlmostEqual(60, idle, 1) 
開發者ID:openstack,項目名稱:oslo.service,代碼行數:12,代碼來源:test_periodic.py

示例11: test_external_running_here

# 需要導入模塊: from oslo_service import periodic_task [as 別名]
# 或者: from oslo_service.periodic_task import PeriodicTasks [as 別名]
def test_external_running_here(self):
        self.config(run_external_periodic_tasks=True)

        class Manager(periodic_task.PeriodicTasks):

            @periodic_task.periodic_task(spacing=200, external_process_ok=True)
            def bar(self):
                return 'bar'

        m = Manager(self.conf)
        self.assertThat(m._periodic_tasks, matchers.HasLength(1)) 
開發者ID:openstack,項目名稱:oslo.service,代碼行數:13,代碼來源:test_periodic.py


注:本文中的oslo_service.periodic_task.PeriodicTasks方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。