< Summary - Jellyfin

Information
Class: Jellyfin.Server.HealthChecks.DbContextFactoryHealthCheck<T>
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/HealthChecks/DbContextFactoryHealthCheck.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 2
Coverable lines: 2
Total lines: 43
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%

File(s)

/srv/git/jellyfin/Jellyfin.Server/HealthChecks/DbContextFactoryHealthCheck.cs

#LineLine coverage
 1using System;
 2using System.Threading;
 3using System.Threading.Tasks;
 4using Microsoft.EntityFrameworkCore;
 5using Microsoft.Extensions.Diagnostics.HealthChecks;
 6
 7namespace Jellyfin.Server.HealthChecks;
 8
 9/// <summary>
 10/// Implementation of the <see cref="DbContextHealthCheck{TContext}"/> for a <see cref="IDbContextFactory{TContext}"/>.
 11/// </summary>
 12/// <typeparam name="TContext">The type of database context.</typeparam>
 13public class DbContextFactoryHealthCheck<TContext> : IHealthCheck
 14    where TContext : DbContext
 15{
 16    private readonly IDbContextFactory<TContext> _dbContextFactory;
 17
 18    /// <summary>
 19    /// Initializes a new instance of the <see cref="DbContextFactoryHealthCheck{TContext}"/> class.
 20    /// </summary>
 21    /// <param name="contextFactory">Instance of the <see cref="IDbContextFactory{TContext}"/> interface.</param>
 22    public DbContextFactoryHealthCheck(IDbContextFactory<TContext> contextFactory)
 23    {
 024        _dbContextFactory = contextFactory;
 025    }
 26
 27    /// <inheritdoc />
 28    public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToke
 29    {
 30        ArgumentNullException.ThrowIfNull(context);
 31
 32        var dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken).ConfigureAwait(false);
 33        await using (dbContext.ConfigureAwait(false))
 34        {
 35            if (await dbContext.Database.CanConnectAsync(cancellationToken).ConfigureAwait(false))
 36            {
 37                return HealthCheckResult.Healthy();
 38            }
 39        }
 40
 41        return HealthCheckResult.Unhealthy();
 42    }
 43}