Skip to content

Fill the forecast-prefetch cold-start gap with a startup catch-up - #27

Merged
piomar123 merged 1 commit into
mainfrom
solcast-prefetch-cold-start
Sep 15, 2026
Merged

piomar123 merged 1 commit into
mainfrom
solcast-prefetch-cold-start

Conversation

@piomar123

Copy link
Copy Markdown
Owner

Fill the forecast-prefetch cold-start gap with a startup catch-up

ForecastPrefetchThread only refreshed forecast/actuals data at its fixed daily wake times (06:00/11:00/21:00 forecast, 23:00 actuals). A restart — deploy, crash, dev testing — left /forecast empty until the next scheduled wake, since forecast_history.get_latest_merged (unlike rce_prefetch.py's read path) has no live-fetch fallback on a miss.

Fix: a run_catch_up() pass runs once before the wait loop. Per source, it fetches immediately only if nothing's been written since the most recent wake time that should already have fired (has_fetched_since + last_wake_time, the backward-looking mirror of next_wake_time) — a quick restart minutes after a real fetch costs nothing extra; a genuine cold start fills what's missing once.

Solcast actuals catch-up never writes today (fetch_and_store_solcast_actuals's new max_date param) — writing a partial "today" snapshot mid-day risks permanently stranding that day with holes if the service goes down again before the normal 23:00 slot completes it. Today's actuals stay that slot's job.

Tests added for last_wake_time, has_fetched_since, max_date filtering, and run_catch_up's staleness gating. Full suite (202 tests) green, including under TZ=UTC.

ForecastPrefetchThread only refreshed forecast/actuals data at its fixed
daily wake times, so a restart (deploy, crash, dev testing) left
/forecast empty until the next scheduled wake - unlike rce_prefetch.py's
read path, forecast_history.get_latest_merged has no live-fetch fallback
on a miss.

Add run_catch_up(), called once before the wait loop: per source
(meteosource, solcast forecast, solcast actuals), fetch immediately only
if nothing has been written since the most recent wake time that should
already have fired (has_fetched_since + the new last_wake_time, the
backward-looking mirror of next_wake_time). A quick restart minutes after
a real fetch finds everything fresh and costs nothing extra; a genuine
cold start fetches what's missing once.

Solcast actuals catch-up always excludes today (fetch_and_store_solcast_actuals's
new max_date param) - writing a partial "today" snapshot mid-day risks
permanently stranding that day with holes if the service goes down again
before the normal 23:00 slot completes it. Today's actuals stay that
slot's job, never catch-up's.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@piomar123
piomar123 merged commit ff1aa3b into main Sep 15, 2026
1 check passed
@piomar123
piomar123 deleted the solcast-prefetch-cold-start branch September 20, 2026 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant