diff --git a/rhodecode/lib/celerylib/__init__.py b/rhodecode/lib/celerylib/__init__.py --- a/rhodecode/lib/celerylib/__init__.py +++ b/rhodecode/lib/celerylib/__init__.py @@ -63,10 +63,17 @@ def run_task(task, *args, **kwargs): t = None if rhodecode.CELERY_ENABLED and allow_async: + + statsd = StatsdClient.statsd + if statsd: + task_repr = getattr(task, 'name', task) + statsd.incr('rhodecode_celery_task_total', tags=[ + 'task:{}'.format(task_repr) + ]) + try: t = task.apply_async(args=args, kwargs=kwargs) log.debug('executing task %s:%s in async mode', t.task_id, task) - exec_mode = 'async' except socket.error as e: if isinstance(e, IOError) and e.errno == 111: log.error('Unable to connect to celeryd `%s`. Sync execution', e) @@ -82,14 +89,6 @@ def run_task(task, *args, **kwargs): else: log.debug('executing task %s:%s in sync mode', 'TASK', task) - statsd = StatsdClient.statsd - if statsd: - task_repr = getattr(task, 'name', task) - statsd.incr('rhodecode_celery_task_total', tags=[ - 'task:{}'.format(task_repr), - 'mode:{}'.format(exec_mode) - ]) - # we got async task, return it after statsd call if t: return t