using System; using System.Threading; using System.Threading.Tasks; using Jellyfin.Plugin.ShareLinks.Services; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace Jellyfin.Plugin.ShareLinks.Lifecycle; /// /// Runs one cleanup pass at startup so stale records do not linger forever. /// public sealed class StartupCleanupHostedService : BackgroundService { private readonly IShareLinkCleanupService _cleanupService; private readonly ILogger _logger; /// Initializes a new instance of the class. public StartupCleanupHostedService( IShareLinkCleanupService cleanupService, ILogger logger) { _cleanupService = cleanupService; _logger = logger; } /// protected override async Task ExecuteAsync(CancellationToken stoppingToken) { try { await _cleanupService.CleanupAsync(stoppingToken).ConfigureAwait(false); } catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested) { } catch (Exception ex) { _logger.LogWarning(ex, "ShareLinks: startup cleanup failed."); } } }