mirror of
https://github.com/Sea-Haven-Industries/meal-order-manager.git
synced 2026-10-07 05:51:58 +00:00
fix(close-form): accept Fri 00–03 ET catch-up after Thu close cron
EventBridge can deliver past midnight ET; widen the wall-clock guard so a delayed Thursday 23:59 UTC cron still closes the form. Idempotent when already closed. Adds test for early Friday; past-window skip now starts Fri 04:00 ET. Co-authored-by: Adam Moussa <amoussa1229@users.noreply.github.com>
This commit is contained in:
parent
ef0cfe3956
commit
0e26bda83c
2 changed files with 26 additions and 5 deletions
|
|
@ -13,10 +13,15 @@ EASTERN = ZoneInfo("America/New_York")
|
||||||
|
|
||||||
def lambda_handler(event, context):
|
def lambda_handler(event, context):
|
||||||
now_et = datetime.now(EASTERN)
|
now_et = datetime.now(EASTERN)
|
||||||
if not (now_et.weekday() == 3 and now_et.hour >= 23):
|
# EventBridge can fire slightly after midnight ET; accept Thu 23:xx or Fri 00–03
|
||||||
|
# ET so a delayed cron still closes the form. Idempotency: already-closed is a no-op.
|
||||||
|
in_close_window = (now_et.weekday() == 3 and now_et.hour == 23) or (
|
||||||
|
now_et.weekday() == 4 and now_et.hour < 4
|
||||||
|
)
|
||||||
|
if not in_close_window:
|
||||||
return {
|
return {
|
||||||
"status": "skipped",
|
"status": "skipped",
|
||||||
"reason": "outside close window (must be Thursday >= 11 PM ET)",
|
"reason": "outside close window (must be Thu 23:xx or Fri 00–03 ET)",
|
||||||
}
|
}
|
||||||
|
|
||||||
week = event.get("week", current_week())
|
week = event.get("week", current_week())
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,9 @@ class TestCloseFormGuard:
|
||||||
assert result["status"] == "skipped"
|
assert result["status"] == "skipped"
|
||||||
|
|
||||||
@patch("close_form_handler.datetime")
|
@patch("close_form_handler.datetime")
|
||||||
def test_skipped_on_friday(self, mock_dt):
|
def test_skipped_on_friday_after_catchup_window(self, mock_dt):
|
||||||
"""Friday 3am ET (wrong-tz EDT cron during EST) -> skipped."""
|
"""Friday 4am ET -> skipped (past Thu 23 / Fri 00–03 catch-up window)."""
|
||||||
mock_dt.now.return_value = _make_datetime(2026, 5, 15, 3) # Friday 3am
|
mock_dt.now.return_value = _make_datetime(2026, 5, 15, 4) # Friday 4am
|
||||||
|
|
||||||
result = close_form_handler.lambda_handler({}, None)
|
result = close_form_handler.lambda_handler({}, None)
|
||||||
|
|
||||||
|
|
@ -89,6 +89,22 @@ class TestCloseFormGuard:
|
||||||
|
|
||||||
assert result["status"] == "closed"
|
assert result["status"] == "closed"
|
||||||
|
|
||||||
|
@patch("close_form_handler.set_form_status")
|
||||||
|
@patch("close_form_handler.get_form_status", return_value="open")
|
||||||
|
@patch("close_form_handler.current_week", return_value="2026-W19")
|
||||||
|
@patch("close_form_handler._lambda")
|
||||||
|
@patch("close_form_handler.datetime")
|
||||||
|
def test_runs_friday_just_after_midnight(
|
||||||
|
self, mock_dt, mock_lam, mock_week, mock_status, mock_set
|
||||||
|
):
|
||||||
|
"""Friday 12:30am ET -> proceeds (delayed EventBridge past Thu 23:59)."""
|
||||||
|
mock_dt.now.return_value = _make_datetime(2026, 5, 15, 0, 30)
|
||||||
|
|
||||||
|
result = close_form_handler.lambda_handler({}, None)
|
||||||
|
|
||||||
|
assert result["status"] == "closed"
|
||||||
|
mock_set.assert_called_once()
|
||||||
|
|
||||||
@patch("close_form_handler.get_form_status", return_value="closed")
|
@patch("close_form_handler.get_form_status", return_value="closed")
|
||||||
@patch("close_form_handler.current_week", return_value="2026-W19")
|
@patch("close_form_handler.current_week", return_value="2026-W19")
|
||||||
@patch("close_form_handler.datetime")
|
@patch("close_form_handler.datetime")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue