Generator
services/generator/ is a second Go Lambda. It runs once a day at
09:00 UTC (an EventBridge rule in api-stack.ts), and can also be
invoked by hand.
Why it exists
A schedule like "blood pressure every Monday, Wednesday and Friday at 8 AM" is stored as a rule. But Home, Coming up and the attention checks need the actual upcoming times as rows they can query. So the app materializes them ahead of time (ADR 0012):
- For every live tracker schedule, it writes a scheduled entry for each occurrence over the next 14 days, plus the next one beyond that, because Coming up always shows it.
- For every live coverage schedule, it writes the assignments (who is on duty, when) over the same window.
Times are worked out in the care receiver's own time zone, so "8 AM" stays 8 AM across daylight saving.
How it stays safe to rerun
Each generated entry's ID is derived from its schedule and occurrence time (a UUID v5), so writing the same occurrence twice writes the same row. A rerun, or a rerun after a crash partway, adds nothing twice. When a caregiver creates or changes a schedule, the API calls the same code straight away, so new schedules don't wait for the next daily run.
Where the code is
services/generator/main.go: the Lambda entry; it returns a summary of what it wrote.shared/go-common/v1/generate/: the logic, shared with the API: expanding a rule into occurrences, the 14-day horizon, coverage.
If it fails, the generator errors alarm fires. See Support.