using System.Threading; using System.Threading.Tasks; using Jellyfin.Server.Implementations; using Microsoft.Extensions.Diagnostics.HealthChecks; namespace Jellyfin.Server.HealthChecks { /// /// Checks connectivity to the database. /// public class JellyfinDbHealthCheck : IHealthCheck { private readonly JellyfinDbProvider _dbProvider; /// /// Initializes a new instance of the class. /// /// The jellyfin db provider. public JellyfinDbHealthCheck(JellyfinDbProvider dbProvider) { _dbProvider = dbProvider; } /// public async Task CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) { await using var jellyfinDb = _dbProvider.CreateContext(); if (await jellyfinDb.Database.CanConnectAsync(cancellationToken).ConfigureAwait(false)) { return HealthCheckResult.Healthy("Database connection successful."); } return HealthCheckResult.Unhealthy("Unable to connect to the database."); } } }