本文整理汇总了Python中oslo_service.periodic_task.periodic_task方法的典型用法代码示例。如果您正苦于以下问题:Python periodic_task.periodic_task方法的具体用法?Python periodic_task.periodic_task怎么用?Python periodic_task.periodic_task使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_service.periodic_task
的用法示例。
在下文中一共展示了periodic_task.periodic_task方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from oslo_service import periodic_task [as 别名]
# 或者: from oslo_service.periodic_task import periodic_task [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()
示例2: test_called_correct
# 需要导入模块: from oslo_service import periodic_task [as 别名]
# 或者: from oslo_service.periodic_task import periodic_task [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
示例3: test_raises
# 需要导入模块: from oslo_service import periodic_task [as 别名]
# 或者: from oslo_service.periodic_task import periodic_task [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)
示例4: test_name
# 需要导入模块: from oslo_service import periodic_task [as 别名]
# 或者: from oslo_service.periodic_task import periodic_task [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)
示例5: test_nearest_boundary
# 需要导入模块: from oslo_service import periodic_task [as 别名]
# 或者: from oslo_service.periodic_task import periodic_task [as 别名]
def test_nearest_boundary(self, mock_random, mock_now):
mock_now.return_value = 19
mock_random.return_value = 0
self.assertEqual(17, periodic_task._nearest_boundary(10, 7))
mock_now.return_value = 28
self.assertEqual(27, periodic_task._nearest_boundary(13, 7))
mock_now.return_value = 1841
self.assertEqual(1837, periodic_task._nearest_boundary(781, 88))
mock_now.return_value = 1835
self.assertEqual(mock_now.return_value,
periodic_task._nearest_boundary(None, 88))
# Add 5% jitter
mock_random.return_value = 1.0
mock_now.return_value = 1300
self.assertEqual(1200 + 10, periodic_task._nearest_boundary(1000, 200))
# Add 2.5% jitter
mock_random.return_value = 0.5
mock_now.return_value = 1300
self.assertEqual(1200 + 5, periodic_task._nearest_boundary(1000, 200))
示例6: test_meta
# 需要导入模块: from oslo_service import periodic_task [as 别名]
# 或者: from oslo_service.periodic_task import periodic_task [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'])
示例7: test_periodic_tasks_with_idle
# 需要导入模块: from oslo_service import periodic_task [as 别名]
# 或者: from oslo_service.periodic_task import periodic_task [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)
示例8: test_periodic_tasks_idle_calculation
# 需要导入模块: from oslo_service import periodic_task [as 别名]
# 或者: from oslo_service.periodic_task import periodic_task [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])
示例9: test_periodic_tasks_immediate_runs_now
# 需要导入模块: from oslo_service import periodic_task [as 别名]
# 或者: from oslo_service.periodic_task import periodic_task [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)
示例10: test_periodic_tasks_disabled
# 需要导入模块: from oslo_service import periodic_task [as 别名]
# 或者: from oslo_service.periodic_task import periodic_task [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)
示例11: test_external_running_here
# 需要导入模块: from oslo_service import periodic_task [as 别名]
# 或者: from oslo_service.periodic_task import periodic_task [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))