parent
5c27c6bf56
commit
647e0280ec
@ -1,12 +1,14 @@
|
|||||||
|
using Recyclarr.Cli.Pipelines.Generic;
|
||||||
using Recyclarr.Config.Models;
|
using Recyclarr.Config.Models;
|
||||||
using Recyclarr.ServarrApi.ReleaseProfile;
|
using Recyclarr.ServarrApi.ReleaseProfile;
|
||||||
|
|
||||||
namespace Recyclarr.Cli.Pipelines.ReleaseProfile.PipelinePhases;
|
namespace Recyclarr.Cli.Pipelines.ReleaseProfile.PipelinePhases;
|
||||||
|
|
||||||
public class ReleaseProfileApiFetchPhase(IReleaseProfileApiService rpService)
|
public class ReleaseProfileApiFetchPhase(IReleaseProfileApiService rpService)
|
||||||
|
: IApiFetchPipelinePhase<ReleaseProfilePipelineContext>
|
||||||
{
|
{
|
||||||
public async Task<IList<SonarrReleaseProfile>> Execute(IServiceConfiguration config)
|
public async Task Execute(ReleaseProfilePipelineContext context, IServiceConfiguration config)
|
||||||
{
|
{
|
||||||
return await rpService.GetReleaseProfiles(config);
|
context.ApiFetchOutput = await rpService.GetReleaseProfiles(config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
using Recyclarr.Cli.Pipelines.Generic;
|
||||||
|
|
||||||
|
namespace Recyclarr.Cli.Pipelines.ReleaseProfile.PipelinePhases;
|
||||||
|
|
||||||
|
public class ReleaseProfileLogPhase(ILogger log) : ILogPipelinePhase<ReleaseProfilePipelineContext>
|
||||||
|
{
|
||||||
|
public bool LogConfigPhaseAndExitIfNeeded(ReleaseProfilePipelineContext context)
|
||||||
|
{
|
||||||
|
if (context.ConfigOutput.Any())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debug("No Release Profiles to process");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogPersistenceResults(ReleaseProfilePipelineContext context)
|
||||||
|
{
|
||||||
|
var transactions = context.TransactionOutput;
|
||||||
|
var somethingChanged = false;
|
||||||
|
|
||||||
|
if (transactions.UpdatedProfiles.Count != 0)
|
||||||
|
{
|
||||||
|
log.Information("Update existing profiles: {ProfileNames}", transactions.UpdatedProfiles);
|
||||||
|
somethingChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (transactions.CreatedProfiles.Count != 0)
|
||||||
|
{
|
||||||
|
log.Information("Create new profiles: {ProfileNames}", transactions.CreatedProfiles);
|
||||||
|
somethingChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (transactions.DeletedProfiles.Count != 0)
|
||||||
|
{
|
||||||
|
log.Information("Deleting old release profiles: {ProfileNames}", transactions.DeletedProfiles);
|
||||||
|
somethingChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!somethingChanged)
|
||||||
|
{
|
||||||
|
log.Information("All Release Profiles are up to date!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Recyclarr.Cli.Pipelines.Generic;
|
||||||
|
using Recyclarr.Cli.Pipelines.ReleaseProfile.Models;
|
||||||
|
using Recyclarr.Cli.Pipelines.ReleaseProfile.PipelinePhases;
|
||||||
|
using Recyclarr.Common;
|
||||||
|
using Recyclarr.ServarrApi.ReleaseProfile;
|
||||||
|
|
||||||
|
namespace Recyclarr.Cli.Pipelines.ReleaseProfile;
|
||||||
|
|
||||||
|
[SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification =
|
||||||
|
"Context objects are similar to DTOs; for usability we want to assign not append")]
|
||||||
|
public class ReleaseProfilePipelineContext : IPipelineContext
|
||||||
|
{
|
||||||
|
public string PipelineDescription => "Release Profile Pipeline";
|
||||||
|
public IReadOnlyCollection<SupportedServices> SupportedServiceTypes { get; } = new[]
|
||||||
|
{
|
||||||
|
SupportedServices.Sonarr
|
||||||
|
};
|
||||||
|
|
||||||
|
public IList<ProcessedReleaseProfileData> ConfigOutput { get; set; } = default!;
|
||||||
|
public IList<SonarrReleaseProfile> ApiFetchOutput { get; set; } = default!;
|
||||||
|
public ReleaseProfileTransactionData TransactionOutput { get; set; } = default!;
|
||||||
|
}
|
@ -1,45 +0,0 @@
|
|||||||
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(ILogger log, IReleaseProfilePipelinePhases phases) : ISyncPipeline
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue