mirror of
https://github.com/Sea-Haven-Industries/meal-order-manager.git
synced 2026-09-30 21:43:13 +00:00
- Close form guard: check weekday == 3 (Thursday), not 4 (Friday) — the crons fire at Thursday 11:59 PM ET, when weekday() is 3 - SSM fail-closed: separate _google_auth_configured() (checks env var) from _get_google_client_id() (fetches value). If auth is configured but the SSM fetch fails, return 503 instead of silently falling back to manual auth - Update close_form tests to use Thursday dates - Add test_ssm_failure_fails_closed
36 lines
949 B
Python
36 lines
949 B
Python
import json
|
|
import os
|
|
from datetime import datetime
|
|
from zoneinfo import ZoneInfo
|
|
|
|
import boto3
|
|
|
|
from shared.db import current_week, get_form_status, set_form_status
|
|
|
|
_lambda = boto3.client("lambda")
|
|
EASTERN = ZoneInfo("America/New_York")
|
|
|
|
|
|
def lambda_handler(event, context):
|
|
now_et = datetime.now(EASTERN)
|
|
if not (now_et.weekday() == 3 and now_et.hour >= 23):
|
|
return {
|
|
"status": "skipped",
|
|
"reason": "outside close window (must be Thursday >= 11 PM ET)",
|
|
}
|
|
|
|
week = event.get("week", current_week())
|
|
|
|
status = get_form_status(week)
|
|
if status == "closed":
|
|
return {"status": "already_closed", "week": week}
|
|
|
|
set_form_status(week, "closed")
|
|
|
|
_lambda.invoke(
|
|
FunctionName=os.environ["AGGREGATE_FUNCTION_ARN"],
|
|
InvocationType="Event",
|
|
Payload=json.dumps({"week": week}),
|
|
)
|
|
|
|
return {"status": "closed", "week": week, "aggregate_triggered": True}
|