feat(ops): add database readiness probe

This commit is contained in:
cesnimda
2026-08-31 11:54:36 +02:00
parent 2f146f743c
commit b9e703ee7c
6 changed files with 56 additions and 2 deletions
+17
View File
@@ -645,6 +645,23 @@ app.MapGet("/health", (IConfiguration cfg) => Results.Ok(new
version = BuildMetadata.ResolveVersion(cfg),
})).AllowAnonymous();
// Readiness is separate from liveness: dependency outages must block a release without causing
// Docker to restart an otherwise healthy API process. Keep the public response deliberately terse;
// authorised administrators get detailed database diagnostics from /api/admin/system.
app.MapGet("/ready", async (JobTrackerContext db, CancellationToken cancellationToken) =>
{
try
{
return await db.Database.CanConnectAsync(cancellationToken)
? Results.Ok(new { status = "ready" })
: Results.Json(new { status = "unavailable" }, statusCode: StatusCodes.Status503ServiceUnavailable);
}
catch
{
return Results.Json(new { status = "unavailable" }, statusCode: StatusCodes.Status503ServiceUnavailable);
}
}).AllowAnonymous();
// API schema for tooling/docs. Dev-only: not exposed in production deployments.
if (app.Environment.IsDevelopment())
{