Show More
@@ -31,21 +31,14 b' def run_task(task, *args, **kwargs):' | |||||
31 | return ResultWrapper(task(*args, **kwargs)) |
|
31 | return ResultWrapper(task(*args, **kwargs)) | |
32 |
|
32 | |||
33 |
|
33 | |||
34 | class LockTask(object): |
|
34 | def locked_task(func): | |
35 | """LockTask decorator""" |
|
35 | def __wrapper(func, *fargs, **fkwargs): | |
36 |
|
36 | params = list(fargs) | ||
37 | def __init__(self, func): |
|
37 | params.extend(['%s-%s' % ar for ar in fkwargs.items()]) | |
38 | self.func = func |
|
38 | ||
39 |
|
||||
40 | def __call__(self, func): |
|
|||
41 | return decorator(self.__wrapper, func) |
|
|||
42 |
|
||||
43 | def __wrapper(self, func, *fargs, **fkwargs): |
|
|||
44 | params = [] |
|
|||
45 | params.extend(fargs) |
|
|||
46 | params.extend(fkwargs.values()) |
|
|||
47 | lockkey = 'task_%s' % \ |
|
39 | lockkey = 'task_%s' % \ | |
48 | md5(str(self.func) + '-' + '-'.join(map(str, params))).hexdigest() |
|
40 | md5(str(func.__name__) + '-' + \ | |
|
41 | '-'.join(map(str, params))).hexdigest() | |||
49 | log.info('running task with lockkey %s', lockkey) |
|
42 | log.info('running task with lockkey %s', lockkey) | |
50 | try: |
|
43 | try: | |
51 | l = DaemonLock(lockkey) |
|
44 | l = DaemonLock(lockkey) | |
@@ -55,7 +48,7 b' class LockTask(object):' | |||||
55 | log.info('LockHeld') |
|
48 | log.info('LockHeld') | |
56 | return 'Task with key %s already running' % lockkey |
|
49 | return 'Task with key %s already running' % lockkey | |
57 |
|
50 | |||
58 |
|
51 | return decorator(__wrapper, func) | ||
59 |
|
52 | |||
60 |
|
53 | |||
61 |
|
54 |
@@ -2,7 +2,7 b' from celery.decorators import task' | |||||
2 | from celery.task.sets import subtask |
|
2 | from celery.task.sets import subtask | |
3 | from celeryconfig import PYLONS_CONFIG as config |
|
3 | from celeryconfig import PYLONS_CONFIG as config | |
4 | from pylons.i18n.translation import _ |
|
4 | from pylons.i18n.translation import _ | |
5 |
from pylons_app.lib.celerylib import run_task, |
|
5 | from pylons_app.lib.celerylib import run_task, locked_task | |
6 | from pylons_app.lib.helpers import person |
|
6 | from pylons_app.lib.helpers import person | |
7 | from pylons_app.lib.smtp_mailer import SmtpMailer |
|
7 | from pylons_app.lib.smtp_mailer import SmtpMailer | |
8 | from pylons_app.lib.utils import OrderedDict |
|
8 | from pylons_app.lib.utils import OrderedDict | |
@@ -82,7 +82,7 b' def whoosh_index(repo_location, full_ind' | |||||
82 |
|
82 | |||
83 |
|
83 | |||
84 | @task |
|
84 | @task | |
85 | @LockTask('get_commits_stats') |
|
85 | @locked_task | |
86 | def get_commits_stats(repo_name, ts_min_y, ts_max_y): |
|
86 | def get_commits_stats(repo_name, ts_min_y, ts_max_y): | |
87 | author_key_cleaner = lambda k: person(k).replace('"', "") #for js data compatibilty |
|
87 | author_key_cleaner = lambda k: person(k).replace('"', "") #for js data compatibilty | |
88 |
|
88 |
General Comments 0
You need to be logged in to leave comments.
Login now