Skip to content

Commit

Permalink
Merge pull request #15 from wjdavis5/feature/ImplementAsync
Browse files Browse the repository at this point in the history
Support multiple health check publishers
  • Loading branch information
wjdavis5 authored Sep 26, 2024
2 parents 516625a + 24b4a55 commit 6fffda3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup>
<Version>2.0.0</Version>
<Version>2.0.1</Version>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<Description>Execute health checks in the background and return their results at the health endpoint</Description>
<PackageProjectUrl>https://github.com/wjdavis5/AspNetCore.Diagnostics.HealthChecks.Background</PackageProjectUrl>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using AspNetCore.Diagnostics.HealthChecks.Background;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
Expand Down Expand Up @@ -26,7 +28,7 @@ public BackgroundHealthCheckMiddleware(
RequestDelegate next,
IOptions<HealthCheckOptions> healthCheckOptions,
HealthCheckService healthCheckService,
IHealthCheckPublisher healthCheckPublisher)
IEnumerable<IHealthCheckPublisher> healthCheckPublishers)
{
if (next == null)
{
Expand All @@ -46,8 +48,18 @@ public BackgroundHealthCheckMiddleware(
_next = next;
_healthCheckOptions = healthCheckOptions.Value;
_healthCheckService = healthCheckService;
_healthCheckPublisher = healthCheckPublisher as BackgroundHealthCheckPublisher
?? throw new ArgumentException("Invalid health check publisher type.", nameof(healthCheckPublisher));
foreach(var healthCheckPublisher in healthCheckPublishers)
{
if (healthCheckPublisher is BackgroundHealthCheckPublisher backgroundHealthCheckPublisher)
{
_healthCheckPublisher = backgroundHealthCheckPublisher;
break;
}
}
if (_healthCheckPublisher == null)
{
throw new InvalidOperationException("No BackgroundHealthCheckPublisher found.");
}
}

/// <summary>
Expand Down

0 comments on commit 6fffda3

Please sign in to comment.