Skip to content

Faster initial-retry on cold start when upstream is briefly unreachable #19

@GavT

Description

@GavT

Summary

Follow-up to #16. After that PR, an exception during the initial loadStations() / loadPrices() calls in DataCache.start() is now caught and logged, and the periodic loop continues running. But the periodic loop's interval is priceRefreshMinutes (default 30 minutes), so a cold-start failure means up to 30 minutes of dataLoaded:false before the next attempt — even though the underlying cause (transient 4xx/5xx, allowlist propagation, network blip) is usually resolved within seconds.

Proposed change

Add a short-interval retry loop before falling into the regular schedule:

on start:
  attempt initial load
  if it succeeded: enter regular 30-min loop
  if it failed:
    retry every 30s for up to 5 attempts (~2.5 min total)
    if any succeeds: enter regular loop with normal cadence from that point
    if all fail: enter regular 30-min loop anyway (current behaviour)

This brings the cold-start recovery window from ~30 min down to ~30 sec for the common case, while preserving the "don't hammer a broken upstream forever" property — after 2.5 min of fast retries we fall back to the polite cadence.

Notes

  • Keep the retry loop in DataCache.start() directly; don't introduce a separate scheduler.
  • Each fast-retry attempt should be wrapped in the same try/catch shape fix(backend): refresh loop survives initial-load failures #16 added — log.error(...; will retry shortly) rather than ; will retry on schedule.
  • The fast-retry phase should also respect coroutineContext.isActive so a shutdown during retries doesn't get stuck.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Hardening / refinement / nice-to-have — not blocking launchenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions