##// END OF EJS Templates
celery: don't allow subtasks within tasks
super-admin -
r4875:92d53da0 default
parent child Browse files
Show More
@@ -43,14 +43,26 b' class ResultWrapper(object):'
43
43
44
44
45 def run_task(task, *args, **kwargs):
45 def run_task(task, *args, **kwargs):
46 import celery
46 log.debug('Got task `%s` for execution, celery mode enabled:%s', task, rhodecode.CELERY_ENABLED)
47 log.debug('Got task `%s` for execution, celery mode enabled:%s', task, rhodecode.CELERY_ENABLED)
47 if task is None:
48 if task is None:
48 raise ValueError('Got non-existing task for execution')
49 raise ValueError('Got non-existing task for execution')
49
50
50 exec_mode = 'sync'
51 exec_mode = 'sync'
52 allow_async = True
53
54 # if we're already in a celery task, don't allow async execution again
55 # e.g task within task
56 in_task = celery.current_task
57 if in_task:
58 log.debug('This task in in context of another task: %s, not allowing another async execution', in_task)
59 allow_async = False
60 if kwargs.pop('allow_subtask', False):
61 log.debug('Forced async by allow_async=True flag')
62 allow_async = True
51
63
52 t = None
64 t = None
53 if rhodecode.CELERY_ENABLED:
65 if rhodecode.CELERY_ENABLED and allow_async:
54 try:
66 try:
55 t = task.apply_async(args=args, kwargs=kwargs)
67 t = task.apply_async(args=args, kwargs=kwargs)
56 log.debug('executing task %s:%s in async mode', t.task_id, task)
68 log.debug('executing task %s:%s in async mode', t.task_id, task)
@@ -182,6 +182,8 b' def task_retry_signal('
182 @signals.task_failure.connect
182 @signals.task_failure.connect
183 def task_failure_signal(
183 def task_failure_signal(
184 task_id, exception, args, kwargs, traceback, einfo, **kargs):
184 task_id, exception, args, kwargs, traceback, einfo, **kargs):
185
186 log.error('Task: %s failed !! exc_info: %s', task_id, einfo)
185 from rhodecode.lib.exc_tracking import store_exception
187 from rhodecode.lib.exc_tracking import store_exception
186 from rhodecode.lib.statsd_client import StatsdClient
188 from rhodecode.lib.statsd_client import StatsdClient
187
189
@@ -276,14 +278,8 b' class RequestContextTask(Task):'
276 log.debug('Running Task with class: %s. Request Class: %s',
278 log.debug('Running Task with class: %s. Request Class: %s',
277 self.__class__, req.__class__)
279 self.__class__, req.__class__)
278
280
279 proxy_data = getattr(self.request, 'rhodecode_proxy_data', None)
280 log.debug('celery proxy data:%r', proxy_data)
281
282 user_id = None
281 user_id = None
283 ip_addr = None
282 ip_addr = None
284 if proxy_data:
285 user_id = proxy_data['auth_user']['user_id']
286 ip_addr = proxy_data['auth_user']['ip_addr']
287
283
288 # web case
284 # web case
289 if hasattr(req, 'user'):
285 if hasattr(req, 'user'):
General Comments 0
You need to be logged in to leave comments. Login now