-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e4fbd2
commit 73b6265
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/web/Server/Features/UserSearch/DataForsyningenHealthCheck.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Net; | ||
using Jordnaer.Shared.UserSearch; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
|
||
namespace Jordnaer.Server.Features.UserSearch; | ||
|
||
public class DataForsyningenHealthCheck : IHealthCheck | ||
{ | ||
private readonly IDataForsyningenClient _dataForsyningenClient; | ||
private readonly ILogger<DataForsyningenHealthCheck> _logger; | ||
|
||
public DataForsyningenHealthCheck(IDataForsyningenClient dataForsyningenClient, ILogger<DataForsyningenHealthCheck> logger) | ||
{ | ||
_dataForsyningenClient = dataForsyningenClient; | ||
_logger = logger; | ||
} | ||
|
||
public async Task<HealthCheckResult> CheckHealthAsync( | ||
HealthCheckContext context, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
var pingResult = await _dataForsyningenClient.Ping(cancellationToken); | ||
|
||
if (pingResult.IsSuccessStatusCode) | ||
{ | ||
return HealthCheckResult.Healthy(); | ||
} | ||
if (pingResult.StatusCode is HttpStatusCode.TooManyRequests) | ||
{ | ||
_logger.LogWarning("The {healthCheckName} has hit the rate limit.", nameof(DataForsyningenHealthCheck)); | ||
return HealthCheckResult.Healthy(); | ||
} | ||
if (pingResult.Error is not null) | ||
{ | ||
return new HealthCheckResult(HealthStatus.Degraded, pingResult.Error.Message, pingResult.Error); | ||
} | ||
|
||
return HealthCheckResult.Healthy(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters