Mercurial > kallithea
comparison rhodecode/lib/celerylib/__init__.py @ 679:d85b0948e539 rhodecode-0.0.1.0.2
fixed hooks broken symlink issue
fixed python2.5 crash.
fixed #58 missing graph.js bug
Fixed tests to remove the forked repository when building enviroment
version bump
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 11 Nov 2010 15:03:40 +0100 |
parents | 14559eb34003 |
children | 3d0661b8aaa4 |
comparison
equal
deleted
inserted
replaced
672:6f796f56a64c | 679:d85b0948e539 |
---|---|
10 log = logging.getLogger(__name__) | 10 log = logging.getLogger(__name__) |
11 | 11 |
12 class ResultWrapper(object): | 12 class ResultWrapper(object): |
13 def __init__(self, task): | 13 def __init__(self, task): |
14 self.task = task | 14 self.task = task |
15 | 15 |
16 @LazyProperty | 16 @LazyProperty |
17 def result(self): | 17 def result(self): |
18 return self.task | 18 return self.task |
19 | 19 |
20 def run_task(task, *args, **kwargs): | 20 def run_task(task, *args, **kwargs): |
21 try: | 21 try: |
22 t = task.delay(*args, **kwargs) | 22 t = task.delay(*args, **kwargs) |
23 log.info('running task %s', t.task_id) | 23 log.info('running task %s', t.task_id) |
24 return t | 24 return t |
25 except socket.error, e: | 25 except socket.error, e: |
26 if e.errno == 111: | 26 |
27 try: | |
28 conn_failed = e.errno == 111 | |
29 except AttributeError: | |
30 conn_failed = False | |
31 | |
32 if conn_failed: | |
27 log.debug('Unable to connect to celeryd. Sync execution') | 33 log.debug('Unable to connect to celeryd. Sync execution') |
28 else: | 34 else: |
29 log.error(traceback.format_exc()) | 35 log.debug('Unable to connect to celeryd. Sync execution') |
36 | |
30 except KeyError, e: | 37 except KeyError, e: |
31 log.debug('Unable to connect to celeryd. Sync execution') | 38 log.debug('Unable to connect to celeryd. Sync execution') |
32 except Exception, e: | 39 except Exception, e: |
33 log.error(traceback.format_exc()) | 40 log.error(traceback.format_exc()) |
34 | 41 |
35 return ResultWrapper(task(*args, **kwargs)) | 42 return ResultWrapper(task(*args, **kwargs)) |
36 | 43 |
37 | 44 |
38 def locked_task(func): | 45 def locked_task(func): |
39 def __wrapper(func, *fargs, **fkwargs): | 46 def __wrapper(func, *fargs, **fkwargs): |
40 params = list(fargs) | 47 params = list(fargs) |
41 params.extend(['%s-%s' % ar for ar in fkwargs.items()]) | 48 params.extend(['%s-%s' % ar for ar in fkwargs.items()]) |
42 | 49 |
43 lockkey = 'task_%s' % \ | 50 lockkey = 'task_%s' % \ |
44 md5(str(func.__name__) + '-' + \ | 51 md5(str(func.__name__) + '-' + \ |
45 '-'.join(map(str, params))).hexdigest() | 52 '-'.join(map(str, params))).hexdigest() |
46 log.info('running task with lockkey %s', lockkey) | 53 log.info('running task with lockkey %s', lockkey) |
47 try: | 54 try: |
49 ret = func(*fargs, **fkwargs) | 56 ret = func(*fargs, **fkwargs) |
50 l.release() | 57 l.release() |
51 return ret | 58 return ret |
52 except LockHeld: | 59 except LockHeld: |
53 log.info('LockHeld') | 60 log.info('LockHeld') |
54 return 'Task with key %s already running' % lockkey | 61 return 'Task with key %s already running' % lockkey |
55 | 62 |
56 return decorator(__wrapper, func) | 63 return decorator(__wrapper, func) |
57 | |
58 | 64 |
59 | 65 |
60 | 66 |
61 | 67 |
62 | 68 |
63 | 69 |
64 | 70 |
71 |