34 def start_task(interval, func): |
34 def start_task(interval, func): |
35 lc = task.LoopingCall(func) |
35 lc = task.LoopingCall(func) |
36 lc.start(interval) |
36 lc.start(interval) |
37 |
37 |
38 def start_looping_tasks(repo): |
38 def start_looping_tasks(repo): |
39 for interval, func in repo._looping_tasks: |
39 for interval, func, args in repo._looping_tasks: |
40 repo.info('starting twisted task %s with interval %.2fs', |
40 repo.info('starting twisted task %s with interval %.2fs', |
41 func.__name__, interval) |
41 func.__name__, interval) |
42 def catch_error_func(repo=repo, func=func): |
42 def catch_error_func(repo=repo, func=func, args=args): |
43 try: |
43 try: |
44 func() |
44 func(*args) |
45 except: |
45 except: |
46 repo.exception('error in looping task') |
46 repo.exception('error in looping task') |
47 start_task(interval, catch_error_func) |
47 start_task(interval, catch_error_func) |
48 # ensure no tasks will be further added |
48 # ensure no tasks will be further added |
49 repo._looping_tasks = () |
49 repo._looping_tasks = () |