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

109 lines
3.4 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 refreshing SRF Play content.
/// </summary>
public class ContentRefreshTask : IScheduledTask
{
private readonly ILogger<ContentRefreshTask> _logger;
private readonly ContentRefreshService _contentRefreshService;
/// <summary>
/// Initializes a new instance of the <see cref="ContentRefreshTask"/> class.
/// </summary>
/// <param name="logger">The logger instance.</param>
/// <param name="contentRefreshService">The content refresh service.</param>
public ContentRefreshTask(
ILogger<ContentRefreshTask> logger,
ContentRefreshService contentRefreshService)
{
_logger = logger;
_contentRefreshService = contentRefreshService;
}
/// <inheritdoc />
public string Name => "Refresh SRF Play Content";
/// <inheritdoc />
public string Description => "Refreshes latest and trending content from SRF Play";
/// <inheritdoc />
public string Category => "SRF Play";
/// <inheritdoc />
public string Key => "SRFPlayContentRefresh";
/// <inheritdoc />
public async Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
{
_logger.LogInformation("Starting SRF Play content refresh task");
progress?.Report(0);
try
{
var config = Plugin.Instance?.Configuration;
if (config == null)
{
_logger.LogWarning("Plugin configuration not available");
return;
}
if (!config.EnableLatestContent && !config.EnableTrendingContent)
{
_logger.LogInformation("Content refresh is disabled in configuration");
progress?.Report(100);
return;
}
// Refresh latest content
if (config.EnableLatestContent)
{
_logger.LogInformation("Refreshing latest content");
progress?.Report(25);
await _contentRefreshService.RefreshLatestContentAsync(cancellationToken).ConfigureAwait(false);
}
// Refresh trending content
if (config.EnableTrendingContent)
{
_logger.LogInformation("Refreshing trending content");
progress?.Report(75);
await _contentRefreshService.RefreshTrendingContentAsync(cancellationToken).ConfigureAwait(false);
}
progress?.Report(100);
_logger.LogInformation("SRF Play content refresh task completed successfully");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during SRF Play content refresh task");
throw;
}
}
/// <inheritdoc />
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
var config = Plugin.Instance?.Configuration;
var intervalHours = config?.ContentRefreshIntervalHours ?? 6;
// Run every X hours as configured
return new[]
{
new TaskTriggerInfo
{
Type = TaskTriggerInfo.TriggerInterval,
IntervalTicks = TimeSpan.FromHours(intervalHours).Ticks
}
};
}
}