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(batch-exports): Use events_recent for weekly (#91689)

Tomás Farías Santanadf9d171a5efa
diff --git a/products/batch_exports/backend/temporal/pipeline/query_ranges.py b/products/batch_exports/backend/temporal/pipeline/query_ranges.py
index 50b854c1e5ee..4a41c53a64f5 100644
--- a/products/batch_exports/backend/temporal/pipeline/query_ranges.py
+++ b/products/batch_exports/backend/temporal/pipeline/query_ranges.py
@@ -26,26 +26,26 @@ def use_distributed_events_recent_table(
is_backfill: bool, backfill_details: BackfillDetails | None, data_interval_start: dt.datetime | None
) -> bool:
"""We should use the distributed_events_recent table if it's not a backfill (backfill_details is None) or the
- backfill is within the last 6 days.
+ backfill is within the last 8 days.
- We also check the data_interval_start to make sure it's also within the last 6 days (should always be the case for
+ We also check the data_interval_start to make sure it's also within the last 8 days (should always be the case for
realtime batch exports but for tests it may not be the case)
- The events_recent table, and by extension, the distributed_events_recent table, only have event data from the last 7
- days (we use 6 days to give some buffer).
+ The events_recent table, and by extension, the distributed_events_recent table, only has event data from the last 9
+ days (we cutoff at 8 days to give some extra margin).
"""
if (
not is_backfill
and data_interval_start
- and data_interval_start > (dt.datetime.now(tz=dt.UTC) - dt.timedelta(days=6))
+ and data_interval_start > (dt.datetime.now(tz=dt.UTC) - dt.timedelta(days=8))
):
return True
backfill_start_at = None
if backfill_details and backfill_details.start_at:
backfill_start_at = dt.datetime.fromisoformat(backfill_details.start_at)
- if backfill_start_at and backfill_start_at > (dt.datetime.now(tz=dt.UTC) - dt.timedelta(days=6)):
+ if backfill_start_at and backfill_start_at > (dt.datetime.now(tz=dt.UTC) - dt.timedelta(days=8)):
return True
return False
diff --git a/products/batch_exports/backend/tests/temporal/pipeline/test_query_ranges.py b/products/batch_exports/backend/tests/temporal/pipeline/test_query_ranges.py
index deae6835d5e7..9500b06b4a80 100644
--- a/products/batch_exports/backend/tests/temporal/pipeline/test_query_ranges.py
+++ b/products/batch_exports/backend/tests/temporal/pipeline/test_query_ranges.py
@@ -20,17 +20,17 @@ pytestmark = [pytest.mark.django_db]
"data_interval_start": dt.datetime.now(tz=dt.UTC) - dt.timedelta(days=1),
"use_distributed_events_recent_table": True,
},
- # is a backfill within the last 6 days so should use distributed_events_recent table
+ # is a backfill within the last 8 days so should use distributed_events_recent table
{
"is_backfill": True,
"backfill_start_at": dt.datetime.now(tz=dt.UTC) - dt.timedelta(days=1),
"data_interval_start": dt.datetime.now(tz=dt.UTC) - dt.timedelta(days=1),
"use_distributed_events_recent_table": True,
},
- # is a backfill outside the last 6 days so shouldn't use distributed_events_recent table
+ # is a backfill outside the last 8 days so shouldn't use distributed_events_recent table
{
"is_backfill": True,
- "backfill_start_at": dt.datetime.now(tz=dt.UTC) - dt.timedelta(days=7),
+ "backfill_start_at": dt.datetime.now(tz=dt.UTC) - dt.timedelta(days=9),
"data_interval_start": dt.datetime.now(tz=dt.UTC) - dt.timedelta(days=1),
"use_distributed_events_recent_table": False,
},