Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions BlazorBlog/Health/DatabaseHealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ public async Task<HealthCheckResult> CheckHealthAsync(
try
{
await using var db = await _contextFactory.CreateDbContextAsync(cancellationToken);
var canConnect = await db.Database.CanConnectAsync(cancellationToken);
await db.Database.OpenConnectionAsync(cancellationToken);
await db.Database.CloseConnectionAsync();

return canConnect
? HealthCheckResult.Healthy("Database connection is available.")
: HealthCheckResult.Unhealthy("Database connection is not available.");
return HealthCheckResult.Healthy("Database connection is available.");
}
catch (Exception ex)
{
Expand Down
10 changes: 10 additions & 0 deletions BlazorBlog/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ static Task WriteHealthCheckResponseAsync(HttpContext context, HealthReport repo
report.Status,
report.TotalDuration.TotalMilliseconds);

foreach (var (name, entry) in report.Entries.Where(entry => entry.Value.Status != HealthStatus.Healthy))
{
logger.LogWarning(
entry.Exception,
"Readiness check '{Name}' failed with status {Status}: {Description}",
name,
entry.Status,
entry.Description);
}

context.Response.ContentType = "application/json";

var response = new
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
- POSTGRES_USER=${POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in your environment or .env file}
ports:
- "${POSTGRES_PORT:-15432}:5432"
- "127.0.0.1:${POSTGRES_PORT:-15432}:5432"
volumes:
- postgres-data:/var/lib/postgresql/data
healthcheck:
Expand Down
Loading