From e11f72baa7536ebe46d8ea8e91a96531cd54a220 Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Tue, 26 Sep 2023 19:56:04 +0100 Subject: [PATCH] chore: prom count task retry in celery (#17635) --- posthog/celery.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/posthog/celery.py b/posthog/celery.py index 7ed47f2503639..de7069cfccb33 100644 --- a/posthog/celery.py +++ b/posthog/celery.py @@ -6,7 +6,15 @@ from celery import Celery from celery.schedules import crontab -from celery.signals import setup_logging, task_postrun, task_prerun, worker_process_init, task_success, task_failure +from celery.signals import ( + setup_logging, + task_postrun, + task_prerun, + worker_process_init, + task_success, + task_failure, + task_retry, +) from django.conf import settings from django.db import connection from django.dispatch import receiver @@ -43,6 +51,12 @@ labelnames=["task_name"], ) +CELERY_TASK_RETRY_COUNTER = Counter( + "posthog_celery_task_retry", + "task retry signal is dispatched when a task will be retried.", + labelnames=["task_name"], +) + # Using a string here means the worker doesn't have to serialize # the configuration object to child processes. # - namespace='CELERY' means all celery-related configuration keys @@ -242,6 +256,11 @@ def failure_signal_handler(sender, **kwargs): CELERY_TASK_FAILURE_COUNTER.labels(task_name=sender.name).inc() +@task_retry.connect +def retry_signal_handler(sender, **kwargs): + CELERY_TASK_RETRY_COUNTER.labels(task_name=sender.name).inc() + + @task_postrun.connect def teardown_instrumentation(task_id, task, **kwargs): from posthog.clickhouse.query_tagging import reset_query_tags