diff --git a/oslo_service/tests/test_threadgroup.py b/oslo_service/tests/test_threadgroup.py index a4ab26c0..81ca9d40 100644 --- a/oslo_service/tests/test_threadgroup.py +++ b/oslo_service/tests/test_threadgroup.py @@ -55,7 +55,8 @@ class ThreadGroupTestCase(test_base.BaseTestCase): self.tg.add_dynamic_timer_args(foo, ['arg'], {'kwarg': 'kwarg'}, initial_delay=1, - periodic_interval_max=2) + periodic_interval_max=2, + stop_on_exception=False) self.assertEqual(1, len(self.tg.timers)) @@ -83,7 +84,7 @@ class ThreadGroupTestCase(test_base.BaseTestCase): pass self.tg.add_timer_args(1, foo, ['arg'], {'kwarg': 'kwarg'}, - initial_delay=1) + initial_delay=1, stop_on_exception=False) self.assertEqual(1, len(self.tg.timers)) diff --git a/oslo_service/threadgroup.py b/oslo_service/threadgroup.py index bcb79d0b..f64c10fa 100644 --- a/oslo_service/threadgroup.py +++ b/oslo_service/threadgroup.py @@ -89,12 +89,14 @@ class ThreadGroup(object): periodic_interval_max=periodic_interval_max) def add_dynamic_timer_args(self, callback, args=None, kwargs=None, - initial_delay=None, periodic_interval_max=None): + initial_delay=None, periodic_interval_max=None, + stop_on_exception=True): args = args or [] kwargs = kwargs or {} timer = loopingcall.DynamicLoopingCall(callback, *args, **kwargs) timer.start(initial_delay=initial_delay, - periodic_interval_max=periodic_interval_max) + periodic_interval_max=periodic_interval_max, + stop_on_exception=stop_on_exception) self.timers.append(timer) return timer @@ -109,12 +111,13 @@ class ThreadGroup(object): initial_delay=initial_delay) def add_timer_args(self, interval, callback, args=None, kwargs=None, - initial_delay=None): + initial_delay=None, stop_on_exception=True): args = args or [] kwargs = kwargs or {} pulse = loopingcall.FixedIntervalLoopingCall(callback, *args, **kwargs) pulse.start(interval=interval, - initial_delay=initial_delay) + initial_delay=initial_delay, + stop_on_exception=stop_on_exception) self.timers.append(pulse) return pulse diff --git a/releasenotes/notes/timer-stop_on_exception-9f21d7c4d6d1b0d9.yaml b/releasenotes/notes/timer-stop_on_exception-9f21d7c4d6d1b0d9.yaml new file mode 100644 index 00000000..87b58fed --- /dev/null +++ b/releasenotes/notes/timer-stop_on_exception-9f21d7c4d6d1b0d9.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + The ThreadGroup add_timer_args() and add_dynamic_timer_args() methods now + support passing a stop_on_exception=False argument to allow the timer to + keep running even when an exception is raised by the callback function.