Spaces:
Sleeping
Sleeping
George Jieh commited on
Fix backfill: holiday anchor uses as_of when backfilling
Browse files- app/api/trigger.py +15 -11
app/api/trigger.py
CHANGED
|
@@ -55,17 +55,29 @@ def trigger_session(
|
|
| 55 |
if not x_reed_token or not hmac.compare_digest(x_reed_token, expected):
|
| 56 |
raise HTTPException(status_code=401, detail="missing or invalid token")
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
# Holiday skip: GHA cron path goes through this trigger, so the gate must
|
| 59 |
# live here (not just in scheduler.py) for the HF Space deployment.
|
|
|
|
|
|
|
| 60 |
from datetime import datetime as _dt, timezone as _tz
|
| 61 |
from app.market_calendar import is_us_market_holiday
|
| 62 |
-
if
|
| 63 |
-
|
| 64 |
return {
|
| 65 |
"id": None,
|
| 66 |
"headline": "[STUB] skipped (US market holiday)",
|
| 67 |
"session": session,
|
| 68 |
-
"as_of":
|
| 69 |
"skipped": True,
|
| 70 |
}
|
| 71 |
|
|
@@ -75,14 +87,6 @@ def trigger_session(
|
|
| 75 |
logger.warning("provider init failed in trigger: %s", exc)
|
| 76 |
raise HTTPException(status_code=503, detail=f"provider init failed: {exc}")
|
| 77 |
|
| 78 |
-
# Parse as_of query param if provided (backfill mode).
|
| 79 |
-
parsed_as_of = None
|
| 80 |
-
if as_of:
|
| 81 |
-
try:
|
| 82 |
-
parsed_as_of = datetime.fromisoformat(as_of.replace("Z", "+00:00"))
|
| 83 |
-
except ValueError:
|
| 84 |
-
raise HTTPException(status_code=400, detail=f"invalid as_of: {as_of!r}; expected ISO-8601 UTC")
|
| 85 |
-
|
| 86 |
try:
|
| 87 |
digest = generate_digest(
|
| 88 |
session=session,
|
|
|
|
| 55 |
if not x_reed_token or not hmac.compare_digest(x_reed_token, expected):
|
| 56 |
raise HTTPException(status_code=401, detail="missing or invalid token")
|
| 57 |
|
| 58 |
+
# Parse as_of query param if provided (backfill mode). Do this BEFORE
|
| 59 |
+
# the holiday check so the holiday gate can target the backfill date,
|
| 60 |
+
# not today.
|
| 61 |
+
parsed_as_of = None
|
| 62 |
+
if as_of:
|
| 63 |
+
try:
|
| 64 |
+
parsed_as_of = datetime.fromisoformat(as_of.replace("Z", "+00:00"))
|
| 65 |
+
except ValueError:
|
| 66 |
+
raise HTTPException(status_code=400, detail=f"invalid as_of: {as_of!r}; expected ISO-8601 UTC")
|
| 67 |
+
|
| 68 |
# Holiday skip: GHA cron path goes through this trigger, so the gate must
|
| 69 |
# live here (not just in scheduler.py) for the HF Space deployment.
|
| 70 |
+
# For backfill (as_of provided), check the backfill date for holidays,
|
| 71 |
+
# not today.
|
| 72 |
from datetime import datetime as _dt, timezone as _tz
|
| 73 |
from app.market_calendar import is_us_market_holiday
|
| 74 |
+
holiday_anchor = parsed_as_of if parsed_as_of else _dt.now(_tz.utc)
|
| 75 |
+
if config.scheduler.skip_holidays and is_us_market_holiday(holiday_anchor):
|
| 76 |
return {
|
| 77 |
"id": None,
|
| 78 |
"headline": "[STUB] skipped (US market holiday)",
|
| 79 |
"session": session,
|
| 80 |
+
"as_of": holiday_anchor.isoformat(),
|
| 81 |
"skipped": True,
|
| 82 |
}
|
| 83 |
|
|
|
|
| 87 |
logger.warning("provider init failed in trigger: %s", exc)
|
| 88 |
raise HTTPException(status_code=503, detail=f"provider init failed: {exc}")
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
try:
|
| 91 |
digest = generate_digest(
|
| 92 |
session=session,
|