Browse Source

add health check for empty classic schedules

pull/2796/head
Jason Dove 6 months ago
parent
commit
f210edd456
No known key found for this signature in database
  1. 1
      CHANGELOG.md
  2. 5
      ErsatzTV.Core/Health/Checks/IEmptyScheduleHealthCheck.cs
  3. 48
      ErsatzTV.Infrastructure/Health/Checks/EmptyScheduleHealthCheck.cs
  4. 2
      ErsatzTV.Infrastructure/Health/HealthCheckService.cs
  5. 1
      ErsatzTV/Startup.cs

1
CHANGELOG.md

@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- This is most often seen with VAAPI acceleration (radeonsi or i965 drivers)
- Add API endpoint to clean artwork cache folder (on demand)
- POST `/api/maintenance/clean_artwork`
- Add health check to warn about unsupported empty (classic) schedules
### Changed
- Disable automatic artwork database cleanup

5
ErsatzTV.Core/Health/Checks/IEmptyScheduleHealthCheck.cs

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
namespace ErsatzTV.Core.Health.Checks;
public interface IEmptyScheduleHealthCheck : IHealthCheck
{
}

48
ErsatzTV.Infrastructure/Health/Checks/EmptyScheduleHealthCheck.cs

@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
using ErsatzTV.Core.Health;
using ErsatzTV.Core.Health.Checks;
using ErsatzTV.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace ErsatzTV.Infrastructure.Health.Checks;
public class EmptyScheduleHealthCheck(IDbContextFactory<TvContext> dbContextFactory) : BaseHealthCheck, IEmptyScheduleHealthCheck
{
public override string Title => "Empty Schedule";
public async Task<HealthCheckResult> Check(CancellationToken cancellationToken)
{
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
List<int> scheduleIdsWithPlayouts = await dbContext.ProgramSchedules
.TagWithCallSite()
.AsNoTracking()
.Where(s => s.Playouts.Count > 0 && s.Items.Count == 0)
.Select(ps => ps.Id)
.ToListAsync(cancellationToken);
List<int> alternateScheduleIds = await dbContext.ProgramScheduleAlternates
.TagWithCallSite()
.AsNoTracking()
.Where(s => s.ProgramSchedule.Items.Count == 0)
.Select(s => s.ProgramScheduleId)
.ToListAsync(cancellationToken);
var ids = scheduleIdsWithPlayouts.Union(alternateScheduleIds).ToHashSet();
if (ids.Count > 0)
{
List<string> names = await dbContext.ProgramSchedules
.TagWithCallSite()
.AsNoTracking()
.Where(s => ids.Contains(s.Id))
.Select(s => s.Name)
.ToListAsync(cancellationToken);
return WarningResult(
$"There are {names.Count} empty schedules in use, which are NOT supported and WILL cause errors, including: {string.Join(", ", names.OrderBy(identity))}",
$"There are {names.Count} empty schedules in use, which are NOT supported and WILL cause errors");
}
return OkResult();
}
}

2
ErsatzTV.Infrastructure/Health/HealthCheckService.cs

@ -29,6 +29,7 @@ public class HealthCheckService : IHealthCheckService @@ -29,6 +29,7 @@ public class HealthCheckService : IHealthCheckService
IErrorReportsHealthCheck errorReportsHealthCheck,
IUnifiedDockerHealthCheck unifiedDockerHealthCheck,
IDowngradeHealthCheck downgradeHealthCheck,
IEmptyScheduleHealthCheck emptyScheduleHealthCheck,
IMemoryCache memoryCache,
IMediator mediator,
ILogger<HealthCheckService> logger)
@ -49,6 +50,7 @@ public class HealthCheckService : IHealthCheckService @@ -49,6 +50,7 @@ public class HealthCheckService : IHealthCheckService
zeroDurationHealthCheck,
fileNotFoundHealthCheck,
unavailableHealthCheck,
emptyScheduleHealthCheck,
vaapiDriverHealthCheck,
errorReportsHealthCheck
];

1
ErsatzTV/Startup.cs

@ -772,6 +772,7 @@ public class Startup @@ -772,6 +772,7 @@ public class Startup
services.AddScoped<IErrorReportsHealthCheck, ErrorReportsHealthCheck>();
services.AddScoped<IUnifiedDockerHealthCheck, UnifiedDockerHealthCheck>();
services.AddScoped<IDowngradeHealthCheck, DowngradeHealthCheck>();
services.AddScoped<IEmptyScheduleHealthCheck, EmptyScheduleHealthCheck>();
services.AddScoped<IHealthCheckService, HealthCheckService>();
services.AddScoped<IChannelRepository, ChannelRepository>();

Loading…
Cancel
Save