refactor: Use autofac composite for sync pipelines

pull/311/head
Robert Dailey 3 months ago
parent 4ab0e67a7e
commit b0c1423ee4

@ -15,6 +15,7 @@ using Recyclarr.Cli.Pipelines.MediaNaming;
using Recyclarr.Cli.Pipelines.QualityProfile;
using Recyclarr.Cli.Pipelines.QualitySize;
using Recyclarr.Cli.Processors;
using Recyclarr.Cli.Processors.Sync;
using Recyclarr.Common;
using Recyclarr.Compatibility;
using Recyclarr.Config;
@ -76,6 +77,7 @@ public static class CompositionRoot
builder.RegisterModule<MediaNamingAutofacModule>();
builder.RegisterGeneric(typeof(GenericPipelinePhases<>));
builder.RegisterComposite<CompositeSyncPipeline, ISyncPipeline>();
builder.RegisterTypes(
// ORDER HERE IS IMPORTANT!
// There are indirect dependencies between pipelines.

@ -18,7 +18,6 @@ public class ServiceProcessorsAutofacModule : Module
// Sync
builder.RegisterType<SyncProcessor>().As<ISyncProcessor>();
builder.RegisterType<SyncPipelineExecutor>();
// Configuration
builder.RegisterType<ConfigManipulator>().As<IConfigManipulator>();

@ -2,21 +2,19 @@ using Recyclarr.Cli.Console.Settings;
using Recyclarr.Cli.Pipelines;
using Recyclarr.Compatibility;
using Recyclarr.Config.Models;
using Spectre.Console;
namespace Recyclarr.Cli.Processors.Sync;
public class SyncPipelineExecutor(
public class CompositeSyncPipeline(
ILogger log,
IAnsiConsole console,
IOrderedEnumerable<ISyncPipeline> pipelines,
IEnumerable<IPipelineCache> caches,
ServiceAgnosticCapabilityEnforcer enforcer,
IServiceConfiguration config)
IServiceConfiguration config) : ISyncPipeline
{
public async Task Process(ISyncSettings settings, CancellationToken ct)
public virtual async Task Execute(ISyncSettings settings, CancellationToken ct)
{
PrintProcessingHeader();
log.Debug("Processing {Server} server {Name}", config.ServiceType, config.InstanceName);
await enforcer.Check(config, ct);
@ -32,20 +30,4 @@ public class SyncPipelineExecutor(
log.Information("Completed at {Date}", DateTime.Now);
}
private void PrintProcessingHeader()
{
var instanceName = config.InstanceName;
console.WriteLine(
$"""
===========================================
Processing {config.ServiceType} Server: [{instanceName}]
===========================================
""");
log.Debug("Processing {Server} server {Name}", config.ServiceType, instanceName);
}
}

@ -1,19 +1,23 @@
using System.Diagnostics.CodeAnalysis;
using Autofac;
using Recyclarr.Cli.Console.Settings;
using Recyclarr.Cli.Pipelines;
using Recyclarr.Cli.Processors.ErrorHandling;
using Recyclarr.Config;
using Recyclarr.Config.Models;
using Spectre.Console;
namespace Recyclarr.Cli.Processors.Sync;
[UsedImplicitly]
public class SyncBasedConfigurationScope(ILifetimeScope scope) : ConfigurationScope(scope)
{
public SyncPipelineExecutor Pipelines { get; } = scope.Resolve<SyncPipelineExecutor>();
public ISyncPipeline Pipelines { get; } = scope.Resolve<ISyncPipeline>();
}
[SuppressMessage("Design", "CA1031:Do not catch general exception types")]
public class SyncProcessor(
IAnsiConsole console,
IConfigurationRegistry configRegistry,
ConfigurationScopeFactory configScopeFactory,
ConsoleExceptionHandler exceptionHandler)
@ -59,7 +63,17 @@ public class SyncProcessor(
try
{
using var scope = configScopeFactory.Start<SyncBasedConfigurationScope>(config);
await scope.Pipelines.Process(settings, ct);
console.WriteLine(
$"""
===========================================
Processing {config.ServiceType} Server: [{config.InstanceName}]
===========================================
""");
await scope.Pipelines.Execute(settings, ct);
}
catch (Exception e)
{

Loading…
Cancel
Save