Show More
@@ -54,15 +54,16 class ResultWrapper(object): | |||||
54 |
|
54 | |||
55 | def run_task(task, *args, **kwargs): |
|
55 | def run_task(task, *args, **kwargs): | |
56 | if rhodecode.CELERY_ENABLED: |
|
56 | if rhodecode.CELERY_ENABLED: | |
|
57 | celery_is_up = False | |||
57 | try: |
|
58 | try: | |
58 | t = task.apply_async(args=args, kwargs=kwargs) |
|
59 | t = task.apply_async(args=args, kwargs=kwargs) | |
59 | log.info('running task %s:%s', t.task_id, task) |
|
60 | log.info('running task %s:%s', t.task_id, task) | |
|
61 | celery_is_up = True | |||
60 | return t |
|
62 | return t | |
61 |
|
63 | |||
62 | except socket.error as e: |
|
64 | except socket.error as e: | |
63 | if isinstance(e, IOError) and e.errno == 111: |
|
65 | if isinstance(e, IOError) and e.errno == 111: | |
64 | log.error('Unable to connect to celeryd. Sync execution') |
|
66 | log.error('Unable to connect to celeryd. Sync execution') | |
65 | rhodecode.CELERY_ENABLED = False |
|
|||
66 | else: |
|
67 | else: | |
67 | log.exception("Exception while connecting to celeryd.") |
|
68 | log.exception("Exception while connecting to celeryd.") | |
68 | except KeyError as e: |
|
69 | except KeyError as e: | |
@@ -71,6 +72,11 def run_task(task, *args, **kwargs): | |||||
71 | log.exception( |
|
72 | log.exception( | |
72 | "Exception while trying to run task asynchronous. " |
|
73 | "Exception while trying to run task asynchronous. " | |
73 | "Fallback to sync execution.") |
|
74 | "Fallback to sync execution.") | |
|
75 | ||||
|
76 | # keep in mind there maybe a subtle race condition where something | |||
|
77 | # depending on rhodecode.CELERY_ENABLED such as @dbsession decorator | |||
|
78 | # will see CELERY_ENABLED as True before this has a chance to set False | |||
|
79 | rhodecode.CELERY_ENABLED = celery_is_up | |||
74 | else: |
|
80 | else: | |
75 | log.debug('executing task %s in sync mode', task) |
|
81 | log.debug('executing task %s in sync mode', task) | |
76 | return ResultWrapper(task(*args, **kwargs)) |
|
82 | return ResultWrapper(task(*args, **kwargs)) |
General Comments 0
You need to be logged in to leave comments.
Login now