:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(billing): run usage reports v2 every 30 minutes (#68203)
Marce Collb2ec68890536
diff --git a/posthog/temporal/schedule.py b/posthog/temporal/schedule.pyindex ff5e42ca19ae..79f9f64b7e8f 100644--- a/posthog/temporal/schedule.py+++ b/posthog/temporal/schedule.py@@ -577,11 +577,11 @@ async def cleanup_legacy_session_summarization_schedules(client: Client):async def create_run_usage_reports_schedule(client: Client):- """Intraday usage report run every 3 hours at minute 45 (8 times a day).+ """Intraday usage report run every 30 minutes.Reports *today's* usage so far (`day_offset=0`) so billing gets freshnumbers throughout the day. A failed slot is superseded by the next one- 3 hours later, so no retries. The complete-day capture is handled by the+ 30 minutes later, so no retries. The complete-day capture is handled by thedaily finalizer schedule (`create_finalize_usage_reports_schedule`). Theworkflow writes per-org usage data to S3 and sends a single SQS pointerto the billing service.@@ -596,15 +596,7 @@ async def create_run_usage_reports_schedule(client: Client):task_queue=settings.BILLING_TASK_QUEUE,retry_policy=common.RetryPolicy(maximum_attempts=1),),- spec=ScheduleSpec(- calendars=[- ScheduleCalendarSpec(- comment="Every 3 hours at minute 45 (01:45, 04:45, ..., 22:45 UTC)",- hour=[ScheduleRange(start=1, end=22, step=3)],- minute=[ScheduleRange(start=45, end=45)],- )- ]- ),+ spec=ScheduleSpec(intervals=[ScheduleIntervalSpec(every=timedelta(minutes=30))]),policy=SchedulePolicy(overlap=ScheduleOverlapPolicy.SKIP),)@@ -625,10 +617,14 @@ async def create_finalize_usage_reports_schedule(client: Client):Reports *yesterday* (`day_offset=1`) once the day is complete — itspointer carries `report_completeness="complete"`, billing's signal thatthe numbers are final for that date.- 02:45 leaves ~2.75 hours for ingestion lag after midnight, gives the- 01:45 intraday slot a full hour to finish (the two schedules' SKIP- policies don't see each other, so spacing is the only concurrency- control), and stays ahead of the legacy Celery run at 03:45 UTC. Unlike+ 02:45 leaves ~2.75 hours for ingestion lag after midnight and stays ahead+ of the legacy Celery run at 03:45 UTC. The intraday schedule now runs+ every 30 minutes, so this slot sits between the 02:30 and 03:00 intraday+ runs rather than clearing them by an hour, and the two schedules' SKIP+ policies don't see each other. A brief overlap is harmless: every run+ writes under its own `{date}/{run_id}` S3 prefix, and the finalizer+ reports yesterday while the intraday runs report today, so overlapping+ runs touch distinct data and at worst add concurrent query load. Unlikethe intraday schedule this run has no later slot to supersede it, so theretry policy keeps re-running it across the day (5m, 10m, ... capped at2h) until it succeeds. Anything longer than that is a manual backfill: