diff --git a/UmlautAdaptarr/Options/GlobalOptions.cs b/UmlautAdaptarr/Options/GlobalOptions.cs index 51452a5..f5c6685 100644 --- a/UmlautAdaptarr/Options/GlobalOptions.cs +++ b/UmlautAdaptarr/Options/GlobalOptions.cs @@ -14,5 +14,11 @@ /// The User-Agent string used in HTTP requests. /// public string UserAgent { get; set; } + + /// + /// The duration in minutes to cache the indexer requests. + /// + public int IndexerRequestsCacheDurationInMinutes { get; set; } = 12; + } } \ No newline at end of file diff --git a/UmlautAdaptarr/Program.cs b/UmlautAdaptarr/Program.cs index 5df6506..1cb0fc5 100644 --- a/UmlautAdaptarr/Program.cs +++ b/UmlautAdaptarr/Program.cs @@ -22,6 +22,11 @@ internal class Program builder.Services.AddSerilog(); + + // Log all configuration values + LogConfigurationValues(configuration); + + // Add services to the container. builder.Services.AddHttpClient("HttpClient").ConfigurePrimaryHttpMessageHandler(() => { @@ -118,4 +123,15 @@ internal class Program //.Enrich.With(new ApiKeyMaskingEnricher("appsettings.json")) // TODO - Not working currently .CreateLogger(); } + + private static void LogConfigurationValues(IConfiguration configuration) + { + Log.Information("Logging all configuration values at startup:"); + + foreach (var kvp in configuration.AsEnumerable()) + { + Log.Information("{Key}: {Value}", kvp.Key, kvp.Value); + } + } + } diff --git a/UmlautAdaptarr/Services/ProxyRequestService.cs b/UmlautAdaptarr/Services/ProxyRequestService.cs index 0011244..f136305 100644 --- a/UmlautAdaptarr/Services/ProxyRequestService.cs +++ b/UmlautAdaptarr/Services/ProxyRequestService.cs @@ -81,7 +81,7 @@ namespace UmlautAdaptarr.Services if (responseMessage.IsSuccessStatusCode) { - _cache.Set(targetUri, responseMessage, TimeSpan.FromMinutes(12)); + _cache.Set(targetUri, responseMessage, TimeSpan.FromMinutes(_options.IndexerRequestsCacheDurationInMinutes)); } return responseMessage; diff --git a/UmlautAdaptarr/Utilities/ServicesExtensions.cs b/UmlautAdaptarr/Utilities/ServicesExtensions.cs index 808906a..594859a 100644 --- a/UmlautAdaptarr/Utilities/ServicesExtensions.cs +++ b/UmlautAdaptarr/Utilities/ServicesExtensions.cs @@ -68,7 +68,7 @@ public static class ServicesExtensions Console.WriteLine(($"Property {failure.PropertyName } failed validation. Error was: {failure.ErrorMessage}")); } - throw new Exception("Please fix cour environment variables and then Start UmlautAdaptarr again"); + throw new Exception("Please fix your environment variables and then Start UmlautAdaptarr again"); } var instanceState = (bool)(typeof(TOptions).GetProperty("Enabled")?.GetValue(option, null) ?? false); diff --git a/UmlautAdaptarr/Validator/GlobalInstanceOptionsValidator.cs b/UmlautAdaptarr/Validator/GlobalInstanceOptionsValidator.cs index e4c90a8..cbf7e48 100644 --- a/UmlautAdaptarr/Validator/GlobalInstanceOptionsValidator.cs +++ b/UmlautAdaptarr/Validator/GlobalInstanceOptionsValidator.cs @@ -6,7 +6,8 @@ namespace UmlautAdaptarr.Validator; public class GlobalInstanceOptionsValidator : AbstractValidator { - private readonly static HttpClient httpClient = new() { + private readonly static HttpClient httpClient = new() + { Timeout = TimeSpan.FromSeconds(3) }; @@ -22,7 +23,7 @@ public class GlobalInstanceOptionsValidator : AbstractValidator x.ApiKey) .NotEmpty().WithMessage("ApiKey is required when Enabled is true."); - + RuleFor(x => x) .MustAsync(BeReachable) .WithMessage("Host/Url is not reachable. Please check your Host or your UmlautAdaptrr Settings"); @@ -35,38 +36,37 @@ public class GlobalInstanceOptionsValidator : AbstractValidator BeReachable(GlobalInstanceOptions opts, CancellationToken cancellationToken) - { - var endTime = DateTime.Now.AddMinutes(3); - var reachable = false; - var url = $"{opts.Host}/api?apikey={opts.ApiKey}"; + private static async Task BeReachable(GlobalInstanceOptions opts, CancellationToken cancellationToken) + { + var endTime = DateTime.Now.AddMinutes(3); + var reachable = false; + var url = $"{opts.Host}/api?apikey={opts.ApiKey}"; - while (DateTime.Now < endTime) - { - try - { - using var response = await httpClient.GetAsync(url, cancellationToken); - if (response.IsSuccessStatusCode) - { - reachable = true; - break; - } - else - { - Console.WriteLine($"Reachable check got unexpected status code {response.StatusCode}."); - } - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } + while (DateTime.Now < endTime) + { + try + { + using var response = await httpClient.GetAsync(url, cancellationToken); + if (response.IsSuccessStatusCode) + { + reachable = true; + break; + } + else + { + Console.WriteLine($"Reachable check got unexpected status code {response.StatusCode}."); + } + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } - // Wait for 15 seconds for next try - Console.WriteLine($"The URL \"{opts.Host}/api?apikey=[REDACTED]\" is not reachable. Next attempt in 15 seconds..."); - Thread.Sleep(15000); - } - - return reachable; - } + // Wait for 15 seconds for next try + Console.WriteLine($"The URL \"{opts.Host}/api?apikey=[REDACTED]\" is not reachable. Next attempt in 15 seconds..."); + Thread.Sleep(15000); + } + return reachable; + } } \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 586a1b2..1468a27 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,7 +23,6 @@ services: - LIDARR__ENABLED=false - LIDARR__HOST=http://localhost:8686 - LIDARR__APIKEY=APIKEY - #- IpLeakTest__Enabled=false # uncomment and set to true to enable IP leak test ### example for multiple instances of same type #- SONARR__0__NAME=NAME 1 (optional) #- SONARR__0__ENABLED=false @@ -33,3 +32,8 @@ services: #- SONARR__1__ENABLED=false #- SONARR__1__HOST=http://localhost:8989 #- SONARR__1__APIKEY=APIKEY + + ### Advanced options (with default values)) + #- IpLeakTest__Enabled=false + #- SETTINGS__IndexerRequestsCacheDurationInMinutes=12 +