From 77e9f2220edb3422b7b32a7e18eecbdd74083885 Mon Sep 17 00:00:00 2001 From: Roque Betiol Jr Date: Thu, 19 Dec 2024 10:59:04 -0300 Subject: [PATCH] Moving analytics to Core app --- src/planscape/analytics/services.py | 20 ------------------- .../{analytics/tasks.py => core/analytics.py} | 19 +++++++++++++++++- src/planscape/planscape/settings.py | 2 +- 3 files changed, 19 insertions(+), 22 deletions(-) delete mode 100644 src/planscape/analytics/services.py rename src/planscape/{analytics/tasks.py => core/analytics.py} (66%) diff --git a/src/planscape/analytics/services.py b/src/planscape/analytics/services.py deleted file mode 100644 index 77dacc1cd..000000000 --- a/src/planscape/analytics/services.py +++ /dev/null @@ -1,20 +0,0 @@ -from typing import AnyStr - -from django.conf import settings -from django.utils.timezone import now - -from analytics.tasks import async_collect_metric - - -def collect_metric(event_name: AnyStr, **kwargs) -> None: - if not settings.ANALYTICS_ENABLED: - return - - event_params = { - "timestamp": now(), - **kwargs - } - if settings.ANALYTICS_DEBUG_MODE: - event_params.update({"debug_mode": True}) - - async_collect_metric.delay(event_name, event_params) diff --git a/src/planscape/analytics/tasks.py b/src/planscape/core/analytics.py similarity index 66% rename from src/planscape/analytics/tasks.py rename to src/planscape/core/analytics.py index 464afbb2a..1dc623fa7 100644 --- a/src/planscape/analytics/tasks.py +++ b/src/planscape/core/analytics.py @@ -2,14 +2,31 @@ import requests import json from typing import Dict, AnyStr, Any + from django.conf import settings +from django.utils.timezone import now from planscape.celery import app log = logging.getLogger(__name__) +def collect_metric(event_name: AnyStr, **kwargs) -> None: + if not settings.ANALYTICS_ENABLED: + return + + event_params = { + "timestamp": now(), + **kwargs + } + if settings.ANALYTICS_DEBUG_MODE: + event_params.update({"debug_mode": True}) + + _async_collect_metric.delay(event_name, event_params) + + + @app.task() -def async_collect_metric(event_name: AnyStr, event_params: Dict[str, Any]) -> None: +def _async_collect_metric(event_name: AnyStr, event_params: Dict[str, Any]) -> None: """ """ if not all( ( diff --git a/src/planscape/planscape/settings.py b/src/planscape/planscape/settings.py index 2e2ebabf3..0c99a3a00 100644 --- a/src/planscape/planscape/settings.py +++ b/src/planscape/planscape/settings.py @@ -404,7 +404,7 @@ "planning.tasks.*": {"queue": "forsys"}, "impacts.tasks.*": {"queue": "impacts"}, "e2e.tasks.*": {"queue": "default"}, - "analytics.tasks.*": {"queue": "default"}, + "core.tasks.*": {"queue": "default"}, } CELERY_ALWAYS_EAGER = config("CELERY_ALWAYS_EAGER", False)