307 config.notification_hooks = True |
307 config.notification_hooks = True |
308 config.instance_hooks = True |
308 config.instance_hooks = True |
309 |
309 |
310 def start_looping_tasks(self): |
310 def start_looping_tasks(self): |
311 assert isinstance(self._looping_tasks, list), 'already started' |
311 assert isinstance(self._looping_tasks, list), 'already started' |
312 for i, (interval, func) in enumerate(self._looping_tasks): |
312 for i, (interval, func, args) in enumerate(self._looping_tasks): |
313 self._looping_tasks[i] = task = LoopTask(interval, func) |
313 self._looping_tasks[i] = task = LoopTask(interval, func, args) |
314 self.info('starting task %s with interval %.2fs', task.name, |
314 self.info('starting task %s with interval %.2fs', task.name, |
315 interval) |
315 interval) |
316 task.start() |
316 task.start() |
317 # ensure no tasks will be further added |
317 # ensure no tasks will be further added |
318 self._looping_tasks = tuple(self._looping_tasks) |
318 self._looping_tasks = tuple(self._looping_tasks) |
319 |
319 |
320 def looping_task(self, interval, func): |
320 def looping_task(self, interval, func, *args): |
321 """register a function to be called every `interval` seconds. |
321 """register a function to be called every `interval` seconds. |
322 |
322 |
323 looping tasks can only be registered during repository initialization, |
323 looping tasks can only be registered during repository initialization, |
324 once done this method will fail. |
324 once done this method will fail. |
325 """ |
325 """ |
326 try: |
326 try: |
327 self._looping_tasks.append( (interval, func) ) |
327 self._looping_tasks.append( (interval, func, args) ) |
328 except AttributeError: |
328 except AttributeError: |
329 raise RuntimeError("can't add looping task once the repository is started") |
329 raise RuntimeError("can't add looping task once the repository is started") |
330 |
330 |
331 def threaded_task(self, func): |
331 def threaded_task(self, func): |
332 """start function in a separated thread""" |
332 """start function in a separated thread""" |