From 0c37f8b7b6288668f6f0c8c0a68e95804e93bd9f Mon Sep 17 00:00:00 2001 From: Raquel Smith Date: Mon, 27 Nov 2023 10:58:21 -0800 Subject: [PATCH] fix: delay usage report sending on sunday (#18900) delay usage report sending on sunday --- posthog/celery.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/posthog/celery.py b/posthog/celery.py index 53c67214783ee..0eaa13fdc5fd4 100644 --- a/posthog/celery.py +++ b/posthog/celery.py @@ -26,9 +26,9 @@ from posthog.cloud_utils import is_cloud from posthog.metrics import pushed_metrics_registry +from posthog.ph_client import get_ph_client from posthog.redis import get_client from posthog.utils import get_crontab -from posthog.ph_client import get_ph_client # set the default Django settings module for the 'celery' program. os.environ.setdefault("DJANGO_SETTINGS_MODULE", "posthog.settings") @@ -148,11 +148,18 @@ def setup_periodic_tasks(sender: Celery, **kwargs): ) # Send all instance usage to the Billing service + # Sends later on Sunday due to clickhouse things that happen on Sunday at ~00:00 UTC sender.add_periodic_task( - crontab(hour="0", minute="5"), + crontab(hour="2", minute="5", day_of_week="sun"), send_org_usage_reports.s(), name="send instance usage report", ) + sender.add_periodic_task( + crontab(hour="0", minute="5", day_of_week="mon,tue,wed,thu,fri,sat"), + send_org_usage_reports.s(), + name="send instance usage report", + ) + # Update local usage info for rate limiting purposes - offset by 30 minutes to not clash with the above sender.add_periodic_task( crontab(hour="*", minute="30"), @@ -905,6 +912,7 @@ def debug_task(self): @app.task(ignore_result=True) def calculate_decide_usage() -> None: from django.db.models import Q + from posthog.models import Team from posthog.models.feature_flag.flag_analytics import capture_team_decide_usage @@ -921,6 +929,7 @@ def calculate_decide_usage() -> None: @app.task(ignore_result=True) def calculate_external_data_rows_synced() -> None: from django.db.models import Q + from posthog.models import Team from posthog.tasks.warehouse import ( capture_workspace_rows_synced_by_team,