From 841ff7b6eed395754ec95ca630996e38ac40b389 Mon Sep 17 00:00:00 2001 From: Qstick Date: Fri, 30 Jul 2021 20:53:12 -0400 Subject: [PATCH] Fixed: Don't fail sync on single app failure --- .../Applications/ApplicationService.cs | 66 ++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core/Applications/ApplicationService.cs b/src/NzbDrone.Core/Applications/ApplicationService.cs index ef25d5118..16344f70a 100644 --- a/src/NzbDrone.Core/Applications/ApplicationService.cs +++ b/src/NzbDrone.Core/Applications/ApplicationService.cs @@ -114,7 +114,12 @@ namespace NzbDrone.Core.Applications var prowlarrMappings = indexerMappings.ToDictionary(i => i.RemoteIndexerId, i => i.IndexerId); //Get Dictionary of Remote Indexers point to Prowlarr and what they are mapped to - var remoteMappings = app.GetIndexerMappings(); + var remoteMappings = ExecuteAction(a => a.GetIndexerMappings(), app); + + if (remoteMappings == null) + { + continue; + } //Add mappings if not already in db, these were setup manually in the app or orphaned by a table wipe foreach (var mapping in remoteMappings) @@ -214,5 +219,64 @@ namespace NzbDrone.Core.Applications _logger.Error(ex, "An error occurred while talking to remote application."); } } + + private TResult ExecuteAction(Func applicationAction, IApplication application) + { + TResult result; + + try + { + result = applicationAction(application); + _applicationStatusService.RecordSuccess(application.Definition.Id); + return result; + } + catch (WebException webException) + { + if (webException.Status == WebExceptionStatus.NameResolutionFailure || + webException.Status == WebExceptionStatus.ConnectFailure) + { + _applicationStatusService.RecordConnectionFailure(application.Definition.Id); + } + else + { + _applicationStatusService.RecordFailure(application.Definition.Id); + } + + if (webException.Message.Contains("502") || webException.Message.Contains("503") || + webException.Message.Contains("timed out")) + { + _logger.Warn("{0} server is currently unavailable. {1}", this, webException.Message); + } + else + { + _logger.Warn("{0} {1}", this, webException.Message); + } + } + catch (TooManyRequestsException ex) + { + if (ex.RetryAfter != TimeSpan.Zero) + { + _applicationStatusService.RecordFailure(application.Definition.Id, ex.RetryAfter); + } + else + { + _applicationStatusService.RecordFailure(application.Definition.Id, TimeSpan.FromHours(1)); + } + + _logger.Warn("API Request Limit reached for {0}", this); + } + catch (HttpException ex) + { + _applicationStatusService.RecordFailure(application.Definition.Id); + _logger.Warn("{0} {1}", this, ex.Message); + } + catch (Exception ex) + { + _applicationStatusService.RecordFailure(application.Definition.Id); + _logger.Error(ex, "An error occurred while talking to remote application."); + } + + return default(TResult); + } } }