Skip to content

: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.

fix(usage-reports): ack all-org producer early (#67386)

Pawel Cebula09c00cb4afa1
diff --git a/posthog/tasks/test/test_usage_report.py b/posthog/tasks/test/test_usage_report.py
index b6650a215522..5955519ab632 100644
--- a/posthog/tasks/test/test_usage_report.py
+++ b/posthog/tasks/test/test_usage_report.py
@@ -60,6 +60,7 @@ from posthog.tasks.usage_report import (
_get_team_report,
_get_teams_for_usage_reports,
capture_event,
+ capture_report,
get_all_event_metrics_in_period,
get_instance_metadata,
get_teams_with_query_metric,
@@ -97,6 +98,14 @@ ErrorTrackingIssue = apps.get_model("error_tracking", "ErrorTrackingIssue")
logger = structlog.get_logger(__name__)
+def test_usage_report_parent_task_acks_early_while_capture_task_acks_late() -> None:
+ assert send_all_org_usage_reports.acks_late is False
+ assert send_all_org_usage_reports.reject_on_worker_lost is False
+
+ assert capture_report.acks_late is True
+ assert capture_report.reject_on_worker_lost is True
+
+
def _setup_replay_data(team_id: int, include_mobile_replay: bool, include_zero_duration: bool = False) -> None:
# recordings in period - 5 sessions
for i in range(1, 6):
diff --git a/posthog/tasks/usage_report.py b/posthog/tasks/usage_report.py
index ac91dda3afb7..2e3a1c66ac33 100644
--- a/posthog/tasks/usage_report.py
+++ b/posthog/tasks/usage_report.py
@@ -116,6 +116,14 @@ USAGE_REPORT_TASK_KWARGS = {
"expires": 14400, # 4h
}
+# The all-org parent can run longer than Redis' default visibility timeout, so
+# late acking it can redeliver the same producer while the first copy is alive.
+USAGE_REPORT_PARENT_TASK_KWARGS = {
+ **USAGE_REPORT_TASK_KWARGS,
+ "acks_late": False,
+ "reject_on_worker_lost": False,
+}
+
@dataclasses.dataclass
class UsageReportCounters:
@@ -2838,7 +2846,7 @@ def _queue_report(producer: Any, organization_id: str, full_report_dict: dict[st
return
-@shared_task(**USAGE_REPORT_TASK_KWARGS, max_retries=3)
+@shared_task(**USAGE_REPORT_PARENT_TASK_KWARGS, max_retries=3)
def send_all_org_usage_reports(
dry_run: bool = False,
at: Optional[str] = None,