Previously, only Sonarr had compatibility checking logic, which also consequently meant that version information was obtained and logged for Sonarr services. However, Radarr had no such checks because compatibility has not yet been an issue. However, we still would like to see version information printed when running Radarr instances.commitlint
parent
934f30d71e
commit
081856e19e
@ -0,0 +1,8 @@
|
||||
namespace TrashLib.Services.Radarr;
|
||||
|
||||
public record RadarrCapabilities(Version Version)
|
||||
{
|
||||
public RadarrCapabilities() : this(new Version())
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using Serilog;
|
||||
using TrashLib.Services.System;
|
||||
|
||||
namespace TrashLib.Services.Radarr;
|
||||
|
||||
public class RadarrCompatibility : ServiceCompatibility<RadarrCapabilities>
|
||||
{
|
||||
public RadarrCompatibility(ISystemApiService api, ILogger log)
|
||||
: base(api, log)
|
||||
{
|
||||
}
|
||||
|
||||
protected override RadarrCapabilities BuildCapabilitiesObject(Version version)
|
||||
{
|
||||
return new RadarrCapabilities(version);
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace TrashLib.Services.System.Dto;
|
||||
|
||||
public record SystemStatus(
|
||||
string AppName,
|
||||
string Version
|
||||
);
|
@ -0,0 +1,8 @@
|
||||
using TrashLib.Services.System.Dto;
|
||||
|
||||
namespace TrashLib.Services.System;
|
||||
|
||||
public interface ISystemApiService
|
||||
{
|
||||
Task<SystemStatus> GetStatus();
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
using System.Reactive.Concurrency;
|
||||
using System.Reactive.Linq;
|
||||
using Serilog;
|
||||
using TrashLib.Services.System.Dto;
|
||||
|
||||
namespace TrashLib.Services.System;
|
||||
|
||||
public abstract class ServiceCompatibility<T> where T : new()
|
||||
{
|
||||
private readonly ILogger _log;
|
||||
|
||||
protected ServiceCompatibility(ISystemApiService api, ILogger log)
|
||||
{
|
||||
_log = log;
|
||||
Capabilities = Observable.FromAsync(async () => await api.GetStatus(), NewThreadScheduler.Default)
|
||||
.Timeout(TimeSpan.FromSeconds(15))
|
||||
.Do(LogServiceInfo)
|
||||
.Select(x => new Version(x.Version))
|
||||
.Select(BuildCapabilitiesObject)
|
||||
.Replay(1)
|
||||
.AutoConnect();
|
||||
}
|
||||
|
||||
public IObservable<T> Capabilities { get; }
|
||||
|
||||
private void LogServiceInfo(SystemStatus status)
|
||||
{
|
||||
_log.Debug("{Service} Version: {Version}", status.AppName, status.Version);
|
||||
}
|
||||
|
||||
protected abstract T BuildCapabilitiesObject(Version version);
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
using Flurl;
|
||||
using Flurl.Http;
|
||||
using TrashLib.Config.Services;
|
||||
using TrashLib.Services.System.Dto;
|
||||
|
||||
namespace TrashLib.Services.System;
|
||||
|
||||
public class SystemApiService : ISystemApiService
|
||||
{
|
||||
private readonly IServerInfo _serverInfo;
|
||||
|
||||
public SystemApiService(IServerInfo serverInfo)
|
||||
{
|
||||
_serverInfo = serverInfo;
|
||||
}
|
||||
|
||||
public async Task<SystemStatus> GetStatus()
|
||||
{
|
||||
return await BaseUrl()
|
||||
.AppendPathSegment("system/status")
|
||||
.GetJsonAsync<SystemStatus>();
|
||||
}
|
||||
|
||||
private Url BaseUrl() => _serverInfo.BuildRequest();
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using Autofac;
|
||||
|
||||
namespace TrashLib.Services.System;
|
||||
|
||||
public class SystemServiceAutofacModule : Module
|
||||
{
|
||||
protected override void Load(ContainerBuilder builder)
|
||||
{
|
||||
base.Load(builder);
|
||||
builder.RegisterType<SystemApiService>().As<ISystemApiService>();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue