You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
recyclarr/src/Recyclarr.Cli/Pipelines/ReleaseProfile/ReleaseProfileSyncPipeline.cs

55 lines
1.7 KiB

using Recyclarr.Cli.Console.Settings;
using Recyclarr.Cli.Pipelines.ReleaseProfile.PipelinePhases;
using Recyclarr.Config.Models;
namespace Recyclarr.Cli.Pipelines.ReleaseProfile;
public interface IReleaseProfilePipelinePhases
{
ReleaseProfileConfigPhase ConfigPhase { get; }
ReleaseProfileApiFetchPhase ApiFetchPhase { get; }
ReleaseProfileTransactionPhase TransactionPhase { get; }
Lazy<ReleaseProfilePreviewPhase> PreviewPhase { get; }
ReleaseProfileApiPersistencePhase ApiPersistencePhase { get; }
}
public class ReleaseProfileSyncPipeline : ISyncPipeline
{
private readonly ILogger _log;
private readonly IReleaseProfilePipelinePhases _phases;
public ReleaseProfileSyncPipeline(ILogger log, IReleaseProfilePipelinePhases phases)
{
_log = log;
_phases = phases;
}
public async Task Execute(ISyncSettings settings, IServiceConfiguration config)
{
if (config is not SonarrConfiguration sonarrConfig)
{
_log.Debug("Skipping release profile pipeline because {Instance} is not a Sonarr config",
config.InstanceName);
return;
}
var profiles = _phases.ConfigPhase.Execute(sonarrConfig);
if (profiles is null)
{
_log.Debug("No release profiles to process");
return;
}
var serviceData = await _phases.ApiFetchPhase.Execute(config);
var transactions = _phases.TransactionPhase.Execute(profiles, serviceData);
if (settings.Preview)
{
_phases.PreviewPhase.Value.Execute(transactions);
return;
}
await _phases.ApiPersistencePhase.Execute(config, transactions);
}
}