If UmlautAdaparr was started before the *Arr. The BeReachable test failed, although the config was correct. Now it is tested every 15 seconds for 3 minutes whether the corresponding application can be reached. Before the test fails
This commit is contained in:
Felix Glang
2024-04-29 20:21:46 +02:00
parent c788e0ed76
commit 5931fd6a8a

View File

@@ -15,8 +15,8 @@ namespace UmlautAdaptarr.Validator
RuleFor(x => x.Host) RuleFor(x => x.Host)
.NotEmpty().WithMessage("Host is required when Enabled is true.") .NotEmpty().WithMessage("Host is required when Enabled is true.")
.Must(BeAValidUrl).WithMessage("Host must start with http:// or https:// and be a valid address.") .Must(BeAValidUrl).WithMessage("Host/Url must start with http:// or https:// and be a valid address.")
.Must(BeReachable).WithMessage("Host is not reachable. Please check your Host or your UmlautAdaptrr Settings"); .Must(BeReachable).WithMessage("Host/Url is not reachable. Please check your Host or your UmlautAdaptrr Settings");
RuleFor(x => x.ApiKey) RuleFor(x => x.ApiKey)
.NotEmpty().WithMessage("ApiKey is required when Enabled is true."); .NotEmpty().WithMessage("ApiKey is required when Enabled is true.");
@@ -29,18 +29,37 @@ namespace UmlautAdaptarr.Validator
&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
} }
private bool BeReachable(string url) private static bool BeReachable(string url)
{ {
try DateTime endTime = DateTime.Now.AddMinutes(3);
bool reachable = false;
var request = WebRequest.Create(url);
while (DateTime.Now < endTime)
{ {
var request = WebRequest.Create(url); try
var response = (HttpWebResponse)request.GetResponse(); {
return response.StatusCode == HttpStatusCode.OK;
} var response = (HttpWebResponse)request.GetResponse();
catch reachable = response.StatusCode == HttpStatusCode.OK;
{ if (reachable)
return false; {
break;
}
else
{
Console.WriteLine($"The URL \"{url}\" is not reachable. Next attempt in 15 seconds...");
}
}
catch
{
return false;
}
// Wait for 15 seconds
System.Threading.Thread.Sleep(15000);
} }
return reachable;
} }
} }
} }