# HG changeset patch # User RhodeCode Admin # Date 2023-02-08 13:01:03 # Node ID 2cd8759f99f597bd15443f22946ef023920b6684 # Parent 2aee089bb5b6343f7c17c3130a7967f41dc9d6ed celery: always count tasks even if they fail 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