Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly initialize rabbit health check #786

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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