mirror of
https://github.com/Cleanuparr/Cleanuparr.git
synced 2026-01-10 06:48:25 -05:00
added support for Radarr
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Common.Configuration;
|
||||
using Executable.Jobs;
|
||||
using Infrastructure.Verticals.BlockedTorrent;
|
||||
using Infrastructure.Verticals.Arr;
|
||||
using Infrastructure.Verticals.QueueCleaner;
|
||||
|
||||
namespace Executable;
|
||||
using Quartz;
|
||||
@@ -17,44 +18,46 @@ public static class DependencyInjection
|
||||
|
||||
private static IServiceCollection AddConfiguration(this IServiceCollection services, IConfiguration configuration) =>
|
||||
services
|
||||
.Configure<QuartzConfig>(configuration.GetSection(nameof(QuartzConfig)))
|
||||
.Configure<QBitConfig>(configuration.GetSection(nameof(QBitConfig)))
|
||||
.Configure<SonarrConfig>(configuration.GetSection(nameof(SonarrConfig)));
|
||||
.Configure<QBitConfig>(configuration.GetSection(QBitConfig.SectionName))
|
||||
.Configure<SonarrConfig>(configuration.GetSection(SonarrConfig.SectionName))
|
||||
.Configure<RadarrConfig>(configuration.GetSection(RadarrConfig.SectionName));
|
||||
|
||||
private static IServiceCollection AddServices(this IServiceCollection services) =>
|
||||
services
|
||||
.AddTransient<BlockedTorrentJob>()
|
||||
.AddTransient<BlockedTorrentHandler>();
|
||||
.AddTransient<SonarrClient>()
|
||||
.AddTransient<RadarrClient>()
|
||||
.AddTransient<QueueCleanerJob>()
|
||||
.AddTransient<QueueCleanerHandler>();
|
||||
|
||||
private static IServiceCollection AddQuartzServices(this IServiceCollection services, IConfiguration configuration) =>
|
||||
services
|
||||
.AddQuartz(q =>
|
||||
{
|
||||
QuartzConfig? config = configuration.GetRequiredSection(nameof(QuartzConfig)).Get<QuartzConfig>();
|
||||
TriggersConfig? config = configuration.GetRequiredSection(TriggersConfig.SectionName).Get<TriggersConfig>();
|
||||
|
||||
if (config is null)
|
||||
{
|
||||
throw new NullReferenceException("Quartz configuration is null");
|
||||
}
|
||||
|
||||
q.AddBlockedTorrentJob(config.BlockedTorrentTrigger);
|
||||
q.AddQueueCleanerJob(config.QueueCleaner);
|
||||
})
|
||||
.AddQuartzHostedService(opt =>
|
||||
{
|
||||
opt.WaitForJobsToComplete = true;
|
||||
});
|
||||
|
||||
private static void AddBlockedTorrentJob(this IServiceCollectionQuartzConfigurator q, string trigger)
|
||||
private static void AddQueueCleanerJob(this IServiceCollectionQuartzConfigurator q, string trigger)
|
||||
{
|
||||
q.AddJob<BlockedTorrentJob>(opts =>
|
||||
q.AddJob<QueueCleanerJob>(opts =>
|
||||
{
|
||||
opts.WithIdentity(nameof(BlockedTorrentJob));
|
||||
opts.WithIdentity(nameof(QueueCleanerJob));
|
||||
});
|
||||
|
||||
q.AddTrigger(opts =>
|
||||
{
|
||||
opts.ForJob(nameof(BlockedTorrentJob))
|
||||
.WithIdentity($"{nameof(BlockedTorrentJob)}-trigger")
|
||||
opts.ForJob(nameof(QueueCleanerJob))
|
||||
.WithIdentity($"{nameof(QueueCleanerJob)}-trigger")
|
||||
.WithCronSchedule(trigger);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
using Infrastructure.Verticals.BlockedTorrent;
|
||||
using Quartz;
|
||||
|
||||
namespace Executable.Jobs;
|
||||
|
||||
[DisallowConcurrentExecution]
|
||||
public sealed class BlockedTorrentJob : IJob
|
||||
{
|
||||
private ILogger<BlockedTorrentJob> _logger;
|
||||
private BlockedTorrentHandler _handler;
|
||||
|
||||
public BlockedTorrentJob(ILogger<BlockedTorrentJob> logger, BlockedTorrentHandler handler)
|
||||
{
|
||||
_logger = logger;
|
||||
_handler = handler;
|
||||
}
|
||||
|
||||
public async Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _handler.HandleAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"{nameof(BlockedTorrentJob)} failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
29
code/Executable/Jobs/QueueCleanerJob.cs
Normal file
29
code/Executable/Jobs/QueueCleanerJob.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Infrastructure.Verticals.QueueCleaner;
|
||||
using Quartz;
|
||||
|
||||
namespace Executable.Jobs;
|
||||
|
||||
[DisallowConcurrentExecution]
|
||||
public sealed class QueueCleanerJob : IJob
|
||||
{
|
||||
private ILogger<QueueCleanerJob> _logger;
|
||||
private QueueCleanerHandler _handler;
|
||||
|
||||
public QueueCleanerJob(ILogger<QueueCleanerJob> logger, QueueCleanerHandler handler)
|
||||
{
|
||||
_logger = logger;
|
||||
_handler = handler;
|
||||
}
|
||||
|
||||
public async Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _handler.HandleAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"{nameof(QueueCleanerJob)} failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"QuartzConfig": {
|
||||
"BlockedTorrentTrigger": "0 0/1 * * * ?"
|
||||
"Triggers": {
|
||||
"QueueCleaner": "0 0/1 * * * ?"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,20 +7,30 @@
|
||||
"System.Net.Http.HttpClient": "Error"
|
||||
}
|
||||
},
|
||||
"QuartzConfig": {
|
||||
"BlockedTorrentTrigger": "0 0/5 * * * ?"
|
||||
"Triggers": {
|
||||
"QueueCleaner": "0 0/5 * * * ?"
|
||||
},
|
||||
"QBitConfig": {
|
||||
"qBittorrent": {
|
||||
"Url": "http://localhost:8080",
|
||||
"Username": "",
|
||||
"Password": ""
|
||||
},
|
||||
"SonarrConfig": {
|
||||
"Sonarr": {
|
||||
"Enabled": true,
|
||||
"Instances": [
|
||||
{
|
||||
"Url": "http://localhost:8989",
|
||||
"ApiKey": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
"Radarr": {
|
||||
"Enabled": false,
|
||||
"Instances": [
|
||||
{
|
||||
"Url": "http://localhost:7878",
|
||||
"ApiKey": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user