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.
47 lines
1.4 KiB
47 lines
1.4 KiB
using Recyclarr.Cli.Console.Settings;
|
|
using Recyclarr.Cli.Pipelines.Tags.PipelinePhases;
|
|
using Recyclarr.Config.Models;
|
|
|
|
namespace Recyclarr.Cli.Pipelines.Tags;
|
|
|
|
public interface ITagPipelinePhases
|
|
{
|
|
TagConfigPhase ConfigPhase { get; }
|
|
Lazy<TagPreviewPhase> PreviewPhase { get; }
|
|
TagApiFetchPhase ApiFetchPhase { get; }
|
|
TagTransactionPhase TransactionPhase { get; }
|
|
TagApiPersistencePhase ApiPersistencePhase { get; }
|
|
}
|
|
|
|
public class TagSyncPipeline(
|
|
ILogger log,
|
|
ITagPipelinePhases phases) : ISyncPipeline
|
|
{
|
|
public async Task Execute(ISyncSettings settings, IServiceConfiguration config)
|
|
{
|
|
if (config is not SonarrConfiguration sonarrConfig)
|
|
{
|
|
log.Debug("Skipping tag pipeline because {Instance} is not a Sonarr config", config.InstanceName);
|
|
return;
|
|
}
|
|
|
|
var tags = phases.ConfigPhase.Execute(sonarrConfig);
|
|
if (tags is null)
|
|
{
|
|
log.Debug("No tags to process");
|
|
return;
|
|
}
|
|
|
|
var serviceData = await phases.ApiFetchPhase.Execute(config);
|
|
var transactions = phases.TransactionPhase.Execute(tags, serviceData);
|
|
|
|
if (settings.Preview)
|
|
{
|
|
phases.PreviewPhase.Value.Execute(transactions.AsReadOnly());
|
|
return;
|
|
}
|
|
|
|
await phases.ApiPersistencePhase.Execute(config, transactions);
|
|
}
|
|
}
|