mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
New: Application Status Warnings
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
@@ -14,11 +17,13 @@ namespace NzbDrone.Core.Applications
|
||||
IExecute<ApplicationIndexerSyncCommand>
|
||||
{
|
||||
private readonly IApplicationFactory _applicationsFactory;
|
||||
private readonly IApplicationStatusService _applicationStatusService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public ApplicationService(IApplicationFactory applicationsFactory, Logger logger)
|
||||
public ApplicationService(IApplicationFactory applicationsFactory, IApplicationStatusService applicationStatusService, Logger logger)
|
||||
{
|
||||
_applicationsFactory = applicationsFactory;
|
||||
_applicationStatusService = applicationStatusService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -31,51 +36,103 @@ namespace NzbDrone.Core.Applications
|
||||
{
|
||||
var app = _applicationsFactory.GetInstance(appDefinition);
|
||||
|
||||
app.SyncIndexers();
|
||||
ExecuteAction(a => a.SyncIndexers(), app);
|
||||
}
|
||||
}
|
||||
|
||||
public void HandleAsync(ProviderAddedEvent<IIndexer> message)
|
||||
{
|
||||
var enabledApps = _applicationsFactory.GetAvailableProviders()
|
||||
.Where(n => ((ApplicationDefinition)n.Definition).Enable);
|
||||
var enabledApps = _applicationsFactory.SyncEnabled();
|
||||
|
||||
foreach (var app in enabledApps)
|
||||
{
|
||||
app.AddIndexer((IndexerDefinition)message.Definition);
|
||||
ExecuteAction(a => a.AddIndexer((IndexerDefinition)message.Definition), app);
|
||||
}
|
||||
}
|
||||
|
||||
public void HandleAsync(ProviderDeletedEvent<IIndexer> message)
|
||||
{
|
||||
var enabledApps = _applicationsFactory.GetAvailableProviders()
|
||||
var enabledApps = _applicationsFactory.SyncEnabled()
|
||||
.Where(n => ((ApplicationDefinition)n.Definition).SyncLevel == ApplicationSyncLevel.FullSync);
|
||||
|
||||
foreach (var app in enabledApps)
|
||||
{
|
||||
app.RemoveIndexer(message.ProviderId);
|
||||
ExecuteAction(a => a.RemoveIndexer(message.ProviderId), app);
|
||||
}
|
||||
}
|
||||
|
||||
public void HandleAsync(ProviderUpdatedEvent<IIndexer> message)
|
||||
{
|
||||
var enabledApps = _applicationsFactory.GetAvailableProviders()
|
||||
var enabledApps = _applicationsFactory.SyncEnabled()
|
||||
.Where(n => ((ApplicationDefinition)n.Definition).SyncLevel == ApplicationSyncLevel.FullSync);
|
||||
|
||||
foreach (var app in enabledApps)
|
||||
{
|
||||
app.UpdateIndexer((IndexerDefinition)message.Definition);
|
||||
ExecuteAction(a => a.UpdateIndexer((IndexerDefinition)message.Definition), app);
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(ApplicationIndexerSyncCommand message)
|
||||
{
|
||||
var enabledApps = _applicationsFactory.GetAvailableProviders()
|
||||
.Where(n => ((ApplicationDefinition)n.Definition).Enable);
|
||||
var enabledApps = _applicationsFactory.SyncEnabled();
|
||||
|
||||
foreach (var app in enabledApps)
|
||||
{
|
||||
app.SyncIndexers();
|
||||
ExecuteAction(a => a.SyncIndexers(), app);
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteAction(Action<IApplication> applicationAction, IApplication application)
|
||||
{
|
||||
try
|
||||
{
|
||||
applicationAction(application);
|
||||
_applicationStatusService.RecordSuccess(application.Definition.Id);
|
||||
}
|
||||
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 application.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user