From 94253489746f9d18ea03dadbd148bff68e4f40d0 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Mon, 13 Mar 2023 22:25:45 -0700 Subject: [PATCH] Features/add health (#10) * updated the api to have a basic health check * docker-compose.yaml was updated to add health check --- Newsbot.Collector.Api/Newsbot.Collector.Api.csproj | 3 +++ Newsbot.Collector.Api/Program.cs | 4 ++++ docker-compose.yaml | 11 ++++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Newsbot.Collector.Api/Newsbot.Collector.Api.csproj b/Newsbot.Collector.Api/Newsbot.Collector.Api.csproj index f56a537..32ea9fc 100644 --- a/Newsbot.Collector.Api/Newsbot.Collector.Api.csproj +++ b/Newsbot.Collector.Api/Newsbot.Collector.Api.csproj @@ -7,6 +7,9 @@ + + + diff --git a/Newsbot.Collector.Api/Program.cs b/Newsbot.Collector.Api/Program.cs index 1fe67e6..de8f258 100644 --- a/Newsbot.Collector.Api/Program.cs +++ b/Newsbot.Collector.Api/Program.cs @@ -25,6 +25,9 @@ builder.Services.AddHangfire(f => f.UseMemoryStorage()); builder.Services.AddHangfireServer(); GlobalConfiguration.Configuration.UseSerilogLogProvider(); +builder.Services.AddHealthChecks() + .AddNpgSql(config.GetValue(ConfigConnectionStringConst.Database) ?? ""); + builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); @@ -48,6 +51,7 @@ SetupRecurringJobs(config, Log.Logger); app.UseAuthorization(); +app.MapHealthChecks("/health"); app.MapControllers(); app.Run(); diff --git a/docker-compose.yaml b/docker-compose.yaml index bfc248b..372c939 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -21,9 +21,9 @@ services: - db:/var/lib/postgresql/data healthcheck: test: [ “CMD-SHELL”, “pg_isready” ] - interval: "1s" - timeout: "5s" - retries: 10 + interval: "1m" + timeout: "30s" + retries: 5 adminer: image: adminer @@ -62,6 +62,11 @@ services: # If you want to collect news on Final Fantasy XIV, set this to true FFXIV__IsEnabled: false + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:5000/health"] + interval: "1m" + timeout: "30s" + retries: 5 ports: - "5001:5000" networks: