Skip to content

Commit

Permalink
fix: properly initialize rabbit health check
Browse files Browse the repository at this point in the history
  • Loading branch information
aneojgurhem committed Oct 25, 2024
1 parent e0f7b19 commit 58ebe56
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions Adaptors/RabbitMQ/src/ConnectionRabbit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class ConnectionRabbit : IConnectionRabbit
private readonly ConnectionFactory factory_;
private readonly ILogger<ConnectionRabbit> logger_;
private readonly Amqp options_;
private bool isInitialized_;
private IModel? model_;

public ConnectionRabbit(Amqp options,
Expand All @@ -65,10 +64,10 @@ public Task Init(CancellationToken cancellationToken = default)
public Task<HealthCheckResult> Check(HealthCheckTag tag)
=> tag switch
{
HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_
HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(model_ is not null
? HealthCheckResult.Healthy()
: HealthCheckResult.Unhealthy($"{nameof(ConnectionRabbit)} is not yet initialized.")),
HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && model_ is not null && model_.IsOpen
HealthCheckTag.Liveness => Task.FromResult(model_ is not null && model_.IsOpen
? HealthCheckResult.Healthy()
: HealthCheckResult.Unhealthy($"{nameof(ConnectionRabbit)} not initialized or connection dropped.")),
_ => throw new ArgumentOutOfRangeException(nameof(tag),
Expand All @@ -78,11 +77,8 @@ public Task<HealthCheckResult> Check(HealthCheckTag tag)

public void Dispose()
{
if (isInitialized_)
{
model_!.Close();
model_!.Dispose();
}
model_?.Close();
model_?.Dispose();

connectionSingleizer_.Dispose();

Expand Down

0 comments on commit 58ebe56

Please sign in to comment.