[server/utils] add_looping_task can be used any time (closes #2408814)
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Wed, 04 Jul 2012 11:01:51 +0200
changeset 8446 cae198371548
parent 8445 594efcf51536
child 8448 c5fff93d3a1c
[server/utils] add_looping_task can be used any time (closes #2408814)
server/utils.py
--- a/server/utils.py	Wed Jun 27 18:10:59 2012 +0200
+++ b/server/utils.py	Wed Jul 04 11:01:51 2012 +0200
@@ -218,22 +218,24 @@
         looping tasks can only be registered during repository initialization,
         once done this method will fail.
         """
+        task = LoopTask(self, interval, func, args)
         if self.running:
-            raise RuntimeError("can't add looping task once the repository is started")
-        self._tasks.append( (interval, func, args) )
+            self._start_task(task)
+        else:
+            self._tasks.append(task)
+
+    def _start_task(self, task):
+        self._looping_tasks.append(task)
+        self.info('starting task %s with interval %.2fs', task.name,
+                  task.interval)
+        task.start()
 
     def start(self):
         """Start running looping task"""
         assert self.running == False # bw compat purpose maintly
-
         while self._tasks:
-            interval, func, args = self._tasks.pop()
-            task = LoopTask(self, interval, func, args)
-            self._looping_tasks.append(task)
-            self.info('starting task %s with interval %.2fs', task.name,
-                      interval)
-            task.start()
-
+            task = self._tasks.pop()
+            self._start_task(task)
         self.running = True
 
     def stop(self):