Skip to content

Commit

Permalink
chore: prom count task retry in celery (#17635)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra authored Sep 26, 2023
1 parent d5b912e commit e11f72b
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion posthog/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e11f72b

Please sign in to comment.