mirror of
https://github.com/Cleanuparr/Cleanuparr.git
synced 2026-03-09 09:47:15 -04:00
* fixed unwanted deletion of torrents in downloading metadata state * refactored jobs code * updated arr test data * updated gitignore * updated test configuration and removed dispensable files
60 lines
2.0 KiB
C#
60 lines
2.0 KiB
C#
using Common.Configuration;
|
|
using Domain.Arr.Queue;
|
|
using Domain.Enums;
|
|
using Infrastructure.Verticals.Arr;
|
|
using Infrastructure.Verticals.DownloadClient;
|
|
using Infrastructure.Verticals.Jobs;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace Infrastructure.Verticals.QueueCleaner;
|
|
|
|
public sealed class QueueCleaner : GenericHandler
|
|
{
|
|
public QueueCleaner(
|
|
ILogger<QueueCleaner> logger,
|
|
IOptions<SonarrConfig> sonarrConfig,
|
|
IOptions<RadarrConfig> radarrConfig,
|
|
SonarrClient sonarrClient,
|
|
RadarrClient radarrClient,
|
|
ArrQueueIterator arrArrQueueIterator,
|
|
DownloadServiceFactory downloadServiceFactory
|
|
) : base(logger, sonarrConfig.Value, radarrConfig.Value, sonarrClient, radarrClient, arrArrQueueIterator, downloadServiceFactory)
|
|
{
|
|
}
|
|
|
|
protected override async Task ProcessInstanceAsync(ArrInstance instance, InstanceType instanceType)
|
|
{
|
|
HashSet<int> itemsToBeRefreshed = [];
|
|
ArrClient arrClient = GetClient(instanceType);
|
|
|
|
await _arrArrQueueIterator.Iterate(arrClient, instance, async items =>
|
|
{
|
|
foreach (QueueRecord record in items)
|
|
{
|
|
if (record.Protocol is not "torrent")
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(record.DownloadId))
|
|
{
|
|
_logger.LogDebug("skip | download id is null for {title}", record.Title);
|
|
continue;
|
|
}
|
|
|
|
if (!await _downloadService.ShouldRemoveFromArrQueueAsync(record.DownloadId))
|
|
{
|
|
_logger.LogInformation("skip | {title}", record.Title);
|
|
continue;
|
|
}
|
|
|
|
itemsToBeRefreshed.Add(GetRecordId(instanceType, record));
|
|
|
|
await arrClient.DeleteQueueItemAsync(instance, record);
|
|
}
|
|
});
|
|
|
|
await arrClient.RefreshItemsAsync(instance, itemsToBeRefreshed);
|
|
}
|
|
} |