Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion scripts/execution_report_heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def _month_segments(start: dt.datetime, end: dt.datetime) -> list[str]:
cursor = dt.datetime(start.year, start.month, 1, tzinfo=dt.timezone.utc)
end_cursor = dt.datetime(end.year, end.month, 1, tzinfo=dt.timezone.utc)
while cursor <= end_cursor:
months.append(f"{cursor.year:04d}-{cursor.month:02d}")
month = f"{cursor.year:04d}-{cursor.month:02d}"
months.append(month)
months.append(month.replace("-", "_"))
if cursor.month == 12:
cursor = dt.datetime(cursor.year + 1, 1, 1, tzinfo=dt.timezone.utc)
else:
Expand Down
26 changes: 26 additions & 0 deletions tests/test_execution_report_heartbeat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from __future__ import annotations

import datetime as dt

from scripts import execution_report_heartbeat as heartbeat


def test_report_globs_include_sanitized_month_segments(monkeypatch):
monkeypatch.delenv("RUNTIME_HEARTBEAT_GCS_GLOBS", raising=False)
monkeypatch.delenv("EXECUTION_REPORT_GCS_URI", raising=False)
monkeypatch.delenv("RUNTIME_HEARTBEAT_GCS_URIS", raising=False)
monkeypatch.delenv("RUNTIME_HEARTBEAT_REPORT_PLATFORM", raising=False)
monkeypatch.setenv("FIRSTRADE_GCS_STATE_BUCKET", "runtime-state")
monkeypatch.setenv("FIRSTRADE_STATE_PREFIX", "firstrade-platform")

globs = heartbeat._report_globs(
dt.datetime(2026, 5, 31, tzinfo=dt.timezone.utc),
dt.datetime(2026, 6, 1, tzinfo=dt.timezone.utc),
)

assert globs == [
"gs://runtime-state/firstrade-platform/strategy-runs/**/2026-05/*.json",
"gs://runtime-state/firstrade-platform/strategy-runs/**/2026_05/*.json",
"gs://runtime-state/firstrade-platform/strategy-runs/**/2026-06/*.json",
"gs://runtime-state/firstrade-platform/strategy-runs/**/2026_06/*.json",
]