File: src\Components\Aspire.Qdrant.Client\QdrantHealthCheck.cs
Web Access
Project: src\src\Aspire.Hosting.Qdrant\Aspire.Hosting.Qdrant.csproj (Aspire.Hosting.Qdrant)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
 
using Microsoft.Extensions.Diagnostics.HealthChecks;
 
namespace Aspire.Qdrant.Client;
internal sealed class QdrantHealthCheck : IHealthCheck
{
    private readonly HttpClient _client;
 
    public QdrantHealthCheck(HttpClient client)
    {
        ArgumentNullException.ThrowIfNull(client, nameof(client));
        _client = client;
    }
 
    public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
    {
        try
        {
            var response = await _client.GetAsync("/readyz", cancellationToken).ConfigureAwait(false);
 
            return response.IsSuccessStatusCode
                ? HealthCheckResult.Healthy()
                : new HealthCheckResult(HealthStatus.Unhealthy);
        }
        catch (Exception ex)
        {
            return new HealthCheckResult(context.Registration.FailureStatus, exception: ex);
        }
    }
}