Skip to content

Commit

Permalink
Addresss PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Alirexaa committed Dec 13, 2024
1 parent 57221a8 commit c5b7238
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions src/HealthChecks.Nats/NatsHealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,9 @@ namespace HealthChecks.Nats;
/// </summary>
public sealed class NatsHealthCheck(INatsConnection connection) : IHealthCheck
{
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) =>
await TryConnectAsync(connection).ConfigureAwait(false);

var result = connection.ConnectionState switch
{
NatsConnectionState.Open => HealthCheckResult.Healthy(),
NatsConnectionState.Connecting or NatsConnectionState.Reconnecting => HealthCheckResult.Degraded(),
NatsConnectionState.Closed => await TryConnectAsync(connection).ConfigureAwait(false),
_ => new HealthCheckResult(context.Registration.FailureStatus)
};

return result;
}

private static async Task<HealthCheckResult> TryConnectAsync(INatsConnection natsConnection)
{
try
Expand Down

0 comments on commit c5b7238

Please sign in to comment.