Fix SpaceDevs rate-limiting and cache corruption from throttled responses

Don't write rate-limit/error responses to disk in next_launch_api_data,
so they can't become the "most recent" cache file and cause KeyError crashes
in read_cached_launches. Add defensive results-list checks in
read_cached_launches and get_launches to handle any existing bad files.

Drop refresh=True from the updater's get_active_crewed_flights call so the
2-hour TTL applies; the paginated spacecraft/flight crawl was running on
every hourly cron job and likely causing the burst that triggered throttling.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Edward Betts 2026-02-21 20:50:05 +00:00
parent b4f0a5bf5d
commit 9f881d7177
2 changed files with 24 additions and 11 deletions

View file

@ -321,11 +321,9 @@ def update_thespacedevs(config: flask.config.Config) -> None:
existing_data = agenda.thespacedevs.load_cached_launches(rocket_dir)
assert existing_data
# Refresh active crewed mission cache used by the launches page.
# Failures are handled internally with cache fallback.
active_crewed = agenda.thespacedevs.get_active_crewed_flights(
rocket_dir, refresh=True
)
# Update active crewed mission cache used by the launches page.
# Uses the 2-hour TTL; failures are handled internally with cache fallback.
active_crewed = agenda.thespacedevs.get_active_crewed_flights(rocket_dir)
# Always follow configured slugs
follow_slugs: set[str] = set(config["FOLLOW_LAUNCHES"])