Duncan Tourolle ac6a3842dd
Some checks failed
🏗️ Build Plugin / call (push) Failing after 0s
📝 Create/Update Release Draft & Release Bump PR / call (push) Failing after 0s
🧪 Test Plugin / call (push) Failing after 0s
🔬 Run CodeQL / call (push) Failing after 0s
first commit
2025-11-12 22:05:36 +01:00

112 lines
3.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Plugin.SRFPlay.Services;
using MediaBrowser.Model.Tasks;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.SRFPlay.ScheduledTasks;
/// <summary>
/// Scheduled task for checking and removing expired SRF Play content.
/// </summary>
public class ExpirationCheckTask : IScheduledTask
{
private readonly ILogger<ExpirationCheckTask> _logger;
private readonly ContentExpirationService _expirationService;
/// <summary>
/// Initializes a new instance of the <see cref="ExpirationCheckTask"/> class.
/// </summary>
/// <param name="logger">The logger instance.</param>
/// <param name="expirationService">The content expiration service.</param>
public ExpirationCheckTask(
ILogger<ExpirationCheckTask> logger,
ContentExpirationService expirationService)
{
_logger = logger;
_expirationService = expirationService;
}
/// <inheritdoc />
public string Name => "Check SRF Play Content Expiration";
/// <inheritdoc />
public string Description => "Checks for expired SRF Play content and removes it from the library";
/// <inheritdoc />
public string Category => "SRF Play";
/// <inheritdoc />
public string Key => "SRFPlayExpirationCheck";
/// <inheritdoc />
public async Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
{
_logger.LogInformation("Starting SRF Play expiration check task");
progress?.Report(0);
try
{
var config = Plugin.Instance?.Configuration;
if (config == null)
{
_logger.LogWarning("Plugin configuration not available");
return;
}
// Get expiration statistics first
progress?.Report(25);
var (total, expired, expiringSoon) = await _expirationService.GetExpirationStatisticsAsync(cancellationToken).ConfigureAwait(false);
_logger.LogInformation(
"Expiration statistics - Total: {Total}, Expired: {Expired}, Expiring Soon: {ExpiringSoon}",
total,
expired,
expiringSoon);
if (expired == 0)
{
_logger.LogInformation("No expired content found");
progress?.Report(100);
return;
}
// Remove expired content
progress?.Report(50);
var removedCount = await _expirationService.CheckAndRemoveExpiredContentAsync(cancellationToken).ConfigureAwait(false);
progress?.Report(100);
_logger.LogInformation("SRF Play expiration check task completed. Removed {Count} expired items", removedCount);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during SRF Play expiration check task");
throw;
}
}
/// <inheritdoc />
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
var config = Plugin.Instance?.Configuration;
var intervalHours = config?.ExpirationCheckIntervalHours ?? 24;
// Run daily at 3 AM or every X hours as configured
return new[]
{
new TaskTriggerInfo
{
Type = TaskTriggerInfo.TriggerDaily,
TimeOfDayTicks = TimeSpan.FromHours(3).Ticks
},
new TaskTriggerInfo
{
Type = TaskTriggerInfo.TriggerInterval,
IntervalTicks = TimeSpan.FromHours(intervalHours).Ticks
}
};
}
}