summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-12-19 14:15:34 +0000
committerGerrit Code Review <review@openstack.org>2018-12-19 14:15:34 +0000
commit230aa8947716b20c5ea8ea6d4a5b30093dcbce26 (patch)
tree03fef0136d8032a92b97a93fde6f2d8ac2ba097f
parentb7e697ae4ba36f2d0b58f6ed63ce0948d644709b (diff)
parent48c51fe9cd74d75125d4ee2541fe8a8d5e7462c8 (diff)
Merge "Add stop_on_exception to TG timers"
-rw-r--r--oslo_service/tests/test_threadgroup.py5
-rw-r--r--oslo_service/threadgroup.py11
-rw-r--r--releasenotes/notes/timer-stop_on_exception-9f21d7c4d6d1b0d9.yaml6
3 files changed, 16 insertions, 6 deletions
diff --git a/oslo_service/tests/test_threadgroup.py b/oslo_service/tests/test_threadgroup.py
index a4ab26c..81ca9d4 100644
--- a/oslo_service/tests/test_threadgroup.py
+++ b/oslo_service/tests/test_threadgroup.py
@@ -55,7 +55,8 @@ class ThreadGroupTestCase(test_base.BaseTestCase):
55 55
56 self.tg.add_dynamic_timer_args(foo, ['arg'], {'kwarg': 'kwarg'}, 56 self.tg.add_dynamic_timer_args(foo, ['arg'], {'kwarg': 'kwarg'},
57 initial_delay=1, 57 initial_delay=1,
58 periodic_interval_max=2) 58 periodic_interval_max=2,
59 stop_on_exception=False)
59 60
60 self.assertEqual(1, len(self.tg.timers)) 61 self.assertEqual(1, len(self.tg.timers))
61 62
@@ -83,7 +84,7 @@ class ThreadGroupTestCase(test_base.BaseTestCase):
83 pass 84 pass
84 85
85 self.tg.add_timer_args(1, foo, ['arg'], {'kwarg': 'kwarg'}, 86 self.tg.add_timer_args(1, foo, ['arg'], {'kwarg': 'kwarg'},
86 initial_delay=1) 87 initial_delay=1, stop_on_exception=False)
87 88
88 self.assertEqual(1, len(self.tg.timers)) 89 self.assertEqual(1, len(self.tg.timers))
89 90
diff --git a/oslo_service/threadgroup.py b/oslo_service/threadgroup.py
index bcb79d0..f64c10f 100644
--- a/oslo_service/threadgroup.py
+++ b/oslo_service/threadgroup.py
@@ -89,12 +89,14 @@ class ThreadGroup(object):
89 periodic_interval_max=periodic_interval_max) 89 periodic_interval_max=periodic_interval_max)
90 90
91 def add_dynamic_timer_args(self, callback, args=None, kwargs=None, 91 def add_dynamic_timer_args(self, callback, args=None, kwargs=None,
92 initial_delay=None, periodic_interval_max=None): 92 initial_delay=None, periodic_interval_max=None,
93 stop_on_exception=True):
93 args = args or [] 94 args = args or []
94 kwargs = kwargs or {} 95 kwargs = kwargs or {}
95 timer = loopingcall.DynamicLoopingCall(callback, *args, **kwargs) 96 timer = loopingcall.DynamicLoopingCall(callback, *args, **kwargs)
96 timer.start(initial_delay=initial_delay, 97 timer.start(initial_delay=initial_delay,
97 periodic_interval_max=periodic_interval_max) 98 periodic_interval_max=periodic_interval_max,
99 stop_on_exception=stop_on_exception)
98 self.timers.append(timer) 100 self.timers.append(timer)
99 return timer 101 return timer
100 102
@@ -109,12 +111,13 @@ class ThreadGroup(object):
109 initial_delay=initial_delay) 111 initial_delay=initial_delay)
110 112
111 def add_timer_args(self, interval, callback, args=None, kwargs=None, 113 def add_timer_args(self, interval, callback, args=None, kwargs=None,
112 initial_delay=None): 114 initial_delay=None, stop_on_exception=True):
113 args = args or [] 115 args = args or []
114 kwargs = kwargs or {} 116 kwargs = kwargs or {}
115 pulse = loopingcall.FixedIntervalLoopingCall(callback, *args, **kwargs) 117 pulse = loopingcall.FixedIntervalLoopingCall(callback, *args, **kwargs)
116 pulse.start(interval=interval, 118 pulse.start(interval=interval,
117 initial_delay=initial_delay) 119 initial_delay=initial_delay,
120 stop_on_exception=stop_on_exception)
118 self.timers.append(pulse) 121 self.timers.append(pulse)
119 return pulse 122 return pulse
120 123
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 0000000..87b58fe
--- /dev/null
+++ b/releasenotes/notes/timer-stop_on_exception-9f21d7c4d6d1b0d9.yaml
@@ -0,0 +1,6 @@
1---
2features:
3 - |
4 The ThreadGroup add_timer_args() and add_dynamic_timer_args() methods now
5 support passing a stop_on_exception=False argument to allow the timer to
6 keep running even when an exception is raised by the callback function.