From 31af59418a6995fd7e6813f07e8eaea5747e13ab Mon Sep 17 00:00:00 2001 From: Tushar <30565750+tushar5526@users.noreply.github.com> Date: Tue, 30 Jan 2024 23:56:33 +0530 Subject: [PATCH] feat: send telemetry heartbeat post migrations are applied (#3351) --- api/telemetry/apps.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/api/telemetry/apps.py b/api/telemetry/apps.py index 5e225158ace1..c5b156e49721 100644 --- a/api/telemetry/apps.py +++ b/api/telemetry/apps.py @@ -2,21 +2,27 @@ from django.apps import AppConfig from django.conf import settings +from django.db.models.signals import post_migrate logger = logging.getLogger(__name__) +def send_telemetry_callback(sender, **kwargs): + if settings.ENABLE_TELEMETRY: + try: + from .telemetry import SelfHostedTelemetryWrapper + + telemetry = SelfHostedTelemetryWrapper() + telemetry.send_heartbeat() + except Exception as e: + logger.debug( + "Failed to send Telemetry data to Flagsmith. Exception was %s" % e + ) + pass + + class TelemetryConfig(AppConfig): name = "telemetry" def ready(self): - if settings.ENABLE_TELEMETRY: - try: - from .telemetry import SelfHostedTelemetryWrapper - - telemetry = SelfHostedTelemetryWrapper() - telemetry.send_heartbeat() - except Exception as e: - logger.debug( - "Failed to send Telemetry data to Flagsmith. Exception was %s" % e - ) + post_migrate.connect(send_telemetry_callback, sender=self)