# HG changeset patch # User RhodeCode Admin # Date 2023-02-08 20:39:12 # Node ID 22facf195df7b011fbb9b2d61f7a486535593f97 # Parent 2cd8759f99f597bd15443f22946ef023920b6684 statsd: better task execution reporting on celery 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 @@ -64,13 +64,6 @@ 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) @@ -88,6 +81,13 @@ 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:sync' + ]) # we got async task, return it after statsd call if t: diff --git a/rhodecode/lib/celerylib/loader.py b/rhodecode/lib/celerylib/loader.py --- a/rhodecode/lib/celerylib/loader.py +++ b/rhodecode/lib/celerylib/loader.py @@ -41,6 +41,7 @@ from kombu.serialization import register import rhodecode +from rhodecode.lib.statsd_client import StatsdClient from rhodecode.lib.celerylib.utils import parse_ini_vars, ping_db from rhodecode.lib.ext_json import json from rhodecode.lib.pyramid_utils import bootstrap, setup_logging @@ -182,6 +183,13 @@ def on_beat_init(sender=None, conf=None, @signals.task_prerun.connect def task_prerun_signal(task_id, task, args, **kwargs): ping_db() + statsd = StatsdClient.statsd + if statsd: + task_repr = getattr(task, 'name', task) + statsd.incr('rhodecode_celery_task_total', tags=[ + 'task:{}'.format(task_repr), + 'mode:async' + ]) @signals.task_success.connect @@ -192,6 +200,7 @@ def task_success_signal(result, **kwargs closer() + @signals.task_retry.connect def task_retry_signal( request, reason, einfo, **kwargs):