statsd: better task execution reporting on celery

This commit is contained in:
RhodeCode Admin 2023-02-08 21:39:12 +01:00
parent f8543e9441
commit f051e2a56e
2 changed files with 16 additions and 7 deletions

View file

@ -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:

View file

@ -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, **kwargs):
@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):