Skip to content

Commit 805f89a

Browse files
committed
implemented dbcontext healthcheck
1 parent 6b10aca commit 805f89a

4 files changed

Lines changed: 6 additions & 4 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,4 @@ USER NetEvent
8888
# run
8989
WORKDIR /NetEvent
9090
CMD [ "/bin/sh", "-c", "start-container" ]
91-
HEALTHCHECK --retries=3 --timeout=10s CMD curl --fail http://localhost:5000/healthcheck || exit
91+
HEALTHCHECK --retries=3 --timeout=5s CMD curl --fail http://localhost:5000/healthcheck || exit

NetEvent/Server/NetEvent.Server.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
</PackageReference>
2828
<PackageReference Include="AspNet.Security.OpenId.Steam" Version="6.0.0" />
2929
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
30+
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="6.0.4" />
3031
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.3" />
3132
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.4" />
3233
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.0" />

NetEvent/Server/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
case "sqlite":
1313
{
1414
builder.Services.AddDbContext<ApplicationDbContext, SqliteApplicationDbContext>();
15+
builder.Services.AddHealthChecks().AddDbContextCheck<SqliteApplicationDbContext>();
1516
}
1617
break;
1718
case "psql":
1819
{
1920
builder.Services.AddDbContext<ApplicationDbContext, PsqlApplicationDbContext>();
21+
builder.Services.AddHealthChecks().AddDbContextCheck<PsqlApplicationDbContext>();
2022
}
2123
break;
2224
default:
@@ -52,7 +54,6 @@
5254
builder.Services.AddEndpointsApiExplorer();
5355
builder.Services.AddSwaggerGen();
5456

55-
builder.Services.AddHealthChecks();
5657

5758
var app = builder.Build();
5859

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ services:
2222
healthcheck:
2323
test: ["CMD-SHELL", "curl --fail http://localhost:5000/healthcheck || exit"]
2424
retries: 3
25-
timeout: 10s
25+
timeout: 5s
2626

2727
netevent_psql:
2828
image: 'postgres:latest'
@@ -39,7 +39,7 @@ services:
3939
healthcheck:
4040
test: ["CMD-SHELL", "pg_isready -U ${DBUser} -d ${DBName}"]
4141
retries: 3
42-
timeout: 10s
42+
timeout: 5s
4343

4444
networks:
4545
netevent:

0 commit comments

Comments
 (0)