##// END OF EJS Templates
celery: set global CELERY_ENABLED on any connection error
dan -
r327:cf2d92d8 stable
parent child Browse files
Show More
@@ -54,15 +54,16 b' class ResultWrapper(object):'
54 54
55 55 def run_task(task, *args, **kwargs):
56 56 if rhodecode.CELERY_ENABLED:
57 celery_is_up = False
57 58 try:
58 59 t = task.apply_async(args=args, kwargs=kwargs)
59 60 log.info('running task %s:%s', t.task_id, task)
61 celery_is_up = True
60 62 return t
61 63
62 64 except socket.error as e:
63 65 if isinstance(e, IOError) and e.errno == 111:
64 66 log.error('Unable to connect to celeryd. Sync execution')
65 rhodecode.CELERY_ENABLED = False
66 67 else:
67 68 log.exception("Exception while connecting to celeryd.")
68 69 except KeyError as e:
@@ -71,6 +72,11 b' def run_task(task, *args, **kwargs):'
71 72 log.exception(
72 73 "Exception while trying to run task asynchronous. "
73 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 80 else:
75 81 log.debug('executing task %s in sync mode', task)
76 82 return ResultWrapper(task(*args, **kwargs))
General Comments 0
You need to be logged in to leave comments. Login now