feat: add health check endpoints for Bot and Web
PR Checks / test-and-build (pull_request) Successful in 8m53s
PR Checks / test-and-build (pull_request) Successful in 8m53s
- Web: add /health endpoint with PostgreSQL readiness check (returns 200+JSON or 503) - Web: add /alive endpoint for liveness probe - Bot: add BotHealthCheckHostedService serving /health on port 8081 via HttpListener - Bot: expose port 8081 in Dockerfile and install wget for healthcheck - compose.yaml: add healthcheck sections for bot and web services - tests: add TDD tests for both health endpoints Bump version -> 1.16.0 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Npgsql;
|
||||
|
||||
namespace GmRelay.Web.Health;
|
||||
|
||||
public sealed class NpgsqlHealthCheck(NpgsqlDataSource dataSource) : IHealthCheck
|
||||
{
|
||||
public async Task<HealthCheckResult> CheckHealthAsync(
|
||||
HealthCheckContext context,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await using var connection = await dataSource.OpenConnectionAsync(cancellationToken);
|
||||
await using var command = connection.CreateCommand();
|
||||
command.CommandText = "SELECT 1";
|
||||
await command.ExecuteScalarAsync(cancellationToken);
|
||||
return HealthCheckResult.Healthy();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return HealthCheckResult.Unhealthy("PostgreSQL is unavailable", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user