# HG changeset patch # User Aurelien Campeas # Date 1341392511 -7200 # Node ID cae198371548e120480aa9640cd6ab8488854c25 # Parent 594efcf5153659b9a58904a74fbce8cfeb4ed795 [server/utils] add_looping_task can be used any time (closes #2408814) diff -r 594efcf51536 -r cae198371548 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):