diff rhodecode/lib/celerylib/tasks.py @ 3276:eaa887c6c0af beta

added recursion limit for stats gathering, sometimes it did >1000 loops which lead to python throwing max recursion depth exceeded error. ref #642
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 30 Jan 2013 22:30:52 +0100
parents 99d32d5d70db
children 4c401e37f01d
line wrap: on
line diff
--- a/rhodecode/lib/celerylib/tasks.py	Wed Jan 30 22:10:07 2013 +0100
+++ b/rhodecode/lib/celerylib/tasks.py	Wed Jan 30 22:30:52 2013 +0100
@@ -87,7 +87,7 @@
 
 @task(ignore_result=True)
 @dbsession
-def get_commits_stats(repo_name, ts_min_y, ts_max_y):
+def get_commits_stats(repo_name, ts_min_y, ts_max_y, recurse_limit=100):
     log = get_logger(get_commits_stats)
     DBS = get_session()
     lockkey = __get_lockkey('get_commits_stats', repo_name, ts_min_y,
@@ -240,8 +240,12 @@
         lock.release()
 
         # execute another task if celery is enabled
-        if len(repo.revisions) > 1 and CELERY_ON:
-            run_task(get_commits_stats, repo_name, ts_min_y, ts_max_y)
+        if len(repo.revisions) > 1 and CELERY_ON and recurse_limit > 0:
+            recurse_limit -= 1
+            run_task(get_commits_stats, repo_name, ts_min_y, ts_max_y,
+                     recurse_limit)
+        if recurse_limit <= 0:
+            log.debug('Breaking recursive mode due to reach of recurse limit')
         return True
     except LockHeld:
         log.info('LockHeld')