Skip to content

Commit

Permalink
implemented dbcontext healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Apfelwurm committed Apr 23, 2022
1 parent 6b10aca commit 805f89a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ USER NetEvent
# run
WORKDIR /NetEvent
CMD [ "/bin/sh", "-c", "start-container" ]
HEALTHCHECK --retries=3 --timeout=10s CMD curl --fail http://localhost:5000/healthcheck || exit
HEALTHCHECK --retries=3 --timeout=5s CMD curl --fail http://localhost:5000/healthcheck || exit
1 change: 1 addition & 0 deletions NetEvent/Server/NetEvent.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
</PackageReference>
<PackageReference Include="AspNet.Security.OpenId.Steam" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="6.0.4" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.0" />
Expand Down
3 changes: 2 additions & 1 deletion NetEvent/Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
case "sqlite":
{
builder.Services.AddDbContext<ApplicationDbContext, SqliteApplicationDbContext>();
builder.Services.AddHealthChecks().AddDbContextCheck<SqliteApplicationDbContext>();
}
break;
case "psql":
{
builder.Services.AddDbContext<ApplicationDbContext, PsqlApplicationDbContext>();
builder.Services.AddHealthChecks().AddDbContextCheck<PsqlApplicationDbContext>();
}
break;
default:
Expand Down Expand Up @@ -52,7 +54,6 @@
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddHealthChecks();

var app = builder.Build();

Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
healthcheck:
test: ["CMD-SHELL", "curl --fail http://localhost:5000/healthcheck || exit"]
retries: 3
timeout: 10s
timeout: 5s

netevent_psql:
image: 'postgres:latest'
Expand All @@ -39,7 +39,7 @@ services:
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DBUser} -d ${DBName}"]
retries: 3
timeout: 10s
timeout: 5s

networks:
netevent:
Expand Down

0 comments on commit 805f89a

Please sign in to comment.