33 lines
977 B
C#
33 lines
977 B
C#
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
|
using Qdrant.Client;
|
|
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace NexusReader.Web.Services;
|
|
|
|
public class QdrantHealthCheck : IHealthCheck
|
|
{
|
|
private readonly QdrantClient _qdrantClient;
|
|
|
|
public QdrantHealthCheck(QdrantClient qdrantClient)
|
|
{
|
|
_qdrantClient = qdrantClient;
|
|
}
|
|
|
|
public async Task<HealthCheckResult> CheckHealthAsync(
|
|
HealthCheckContext context, CancellationToken cancellationToken = default)
|
|
{
|
|
try
|
|
{
|
|
// Simple check: query collection existence to verify connection is alive
|
|
_ = await _qdrantClient.CollectionExistsAsync("knowledge_units", cancellationToken);
|
|
return HealthCheckResult.Healthy("Qdrant database is accessible.");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return HealthCheckResult.Unhealthy("Qdrant database health check failed.", ex);
|
|
}
|
|
}
|
|
}
|