Skip to content

Fix health endpoint — return 503 when data cache is not loaded #4

@GavT

Description

@GavT

Summary

GET /api/health always returns HTTP 200, even when DataCache hasn't finished its initial load (e.g. immediately after startup, or if the UK Gov API is down). Load balancers and uptime monitors will consider the service healthy when it isn't.

Location

File: backend/src/main/kotlin/uk/co/fueller/backend/Routes.kt

What to change

  1. Add a isReady(): Boolean method to DataCache that returns true only when at least one station is loaded
  2. In the health route:
    get("/api/health") {
        if (DataCache.isReady()) {
            call.respond(HttpStatusCode.OK, mapOf("status" to "ok", "stations" to DataCache.stationCount()))
        } else {
            call.respond(HttpStatusCode.ServiceUnavailable, mapOf("status" to "loading"))
        }
    }

Workstream: WS1 Phase 1B

Metadata

Metadata

Assignees

No one assigned

    Labels

    WS1-auditWorkstream 1 – Code AuditenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions