[task] allow negative intervals for add_looping_task (closes #2818280)
Instead of rejecting values < 0 with a ValueError, we ignore tasks with
a negative interval. This introduce a simple way to disable task from
configuration.
--- a/doc/3.17.rst Wed Apr 24 11:58:49 2013 +0200
+++ b/doc/3.17.rst Wed Apr 24 12:10:12 2013 +0200
@@ -32,7 +32,8 @@
``ActualNotificationOp`` the new operation use the more efficient *data*
idiom.
-* Looping task can now have a ``0`` interval.
+* Looping task can now have a interval <= ``0``. Negative interval disable the
+ looping task entirely.
Deprecation
--- a/server/utils.py Wed Apr 24 11:58:49 2013 +0200
+++ b/server/utils.py Wed Apr 24 12:10:12 2013 +0200
@@ -219,7 +219,13 @@
def add_looping_task(self, interval, func, *args):
"""register a function to be called every `interval` seconds.
+
+ If interval is negative, no looping task is registered.
"""
+ if interval < 0:
+ self.debug('looping task %s ignored due to interval %f < 0',
+ func_name(func), interval)
+ return
task = LoopTask(self, interval, func, args)
if self.running:
self._start_task(task)