1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

Prevent queue/history from blowing up

This commit is contained in:
Mark McDowall 2014-03-06 22:28:06 -08:00
parent 715f6c3263
commit 9dcd58a631
4 changed files with 60 additions and 14 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Parser;
@ -42,9 +43,21 @@ public override string DownloadNzb(RemoteEpisode remoteEpisode)
public override IEnumerable<QueueItem> GetQueue()
{
var items = _proxy.GetQueue(Settings);
List<NzbgetQueueItem> queue;
foreach (var nzbGetQueueItem in items)
try
{
queue = _proxy.GetQueue(Settings);
}
catch (DownloadClientException ex)
{
_logger.ErrorException(ex.Message, ex);
return Enumerable.Empty<QueueItem>();
}
var queueItems = new List<QueueItem>();
foreach (var nzbGetQueueItem in queue)
{
var queueItem = new QueueItem();
queueItem.Id = nzbGetQueueItem.NzbId.ToString();
@ -60,9 +73,10 @@ public override IEnumerable<QueueItem> GetQueue()
if (remoteEpisode.Series == null) continue;
queueItem.RemoteEpisode = remoteEpisode;
yield return queueItem;
queueItems.Add(queueItem);
}
return queueItems;
}
public override IEnumerable<HistoryItem> GetHistory(int start = 0, int limit = 10)

View File

@ -60,11 +60,21 @@ public override IEnumerable<QueueItem> GetQueue()
{
return _queueCache.Get("queue", () =>
{
var sabQueue = _sabnzbdProxy.GetQueue(0, 0, Settings).Items;
SabnzbdQueue sabQueue;
try
{
sabQueue = _sabnzbdProxy.GetQueue(0, 0, Settings);
}
catch (DownloadClientException ex)
{
_logger.ErrorException(ex.Message, ex);
return Enumerable.Empty<QueueItem>();
}
var queueItems = new List<QueueItem>();
foreach (var sabQueueItem in sabQueue)
foreach (var sabQueueItem in sabQueue.Items)
{
var queueItem = new QueueItem();
queueItem.Id = sabQueueItem.Id;
@ -91,10 +101,21 @@ public override IEnumerable<QueueItem> GetQueue()
public override IEnumerable<HistoryItem> GetHistory(int start = 0, int limit = 10)
{
var items = _sabnzbdProxy.GetHistory(start, limit, Settings).Items;
SabnzbdHistory sabHistory;
try
{
sabHistory = _sabnzbdProxy.GetHistory(start, limit, Settings);
}
catch (DownloadClientException ex)
{
_logger.ErrorException(ex.Message, ex);
return Enumerable.Empty<HistoryItem>();
}
var historyItems = new List<HistoryItem>();
foreach (var sabHistoryItem in items)
foreach (var sabHistoryItem in sabHistory.Items)
{
var historyItem = new HistoryItem();
historyItem.Id = sabHistoryItem.Id;

View File

@ -2,6 +2,7 @@
using System.IO;
using Newtonsoft.Json.Linq;
using NLog;
using NzbDrone.Common;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Download.Clients.Sabnzbd.Responses;
using RestSharp;
@ -112,14 +113,16 @@ private IRestClient BuildClient(string action, SabnzbdSettings settings)
{
var protocol = settings.UseSsl ? "https" : "http";
var url = string.Format(@"{0}://{1}:{2}/api?{3}&apikey={4}&ma_username={5}&ma_password={6}&output=json",
var authentication = settings.ApiKey.IsNullOrWhiteSpace() ?
String.Format("ma_username={0}&ma_password={1}", settings.Username, settings.Password) :
String.Format("apikey={0}", settings.ApiKey);
var url = string.Format(@"{0}://{1}:{2}/api?{3}&{4}&output=json",
protocol,
settings.Host,
settings.Port,
action,
settings.ApiKey,
settings.Username,
settings.Password);
authentication);
_logger.Trace(url);
@ -130,7 +133,7 @@ private void CheckForError(IRestResponse response)
{
if (response.ResponseStatus != ResponseStatus.Completed)
{
throw new ApplicationException("Unable to connect to SABnzbd, please check your settings");
throw new DownloadClientException("Unable to connect to SABnzbd, please check your settings");
}
SabnzbdJsonError result;

View File

@ -81,7 +81,15 @@ private EpisodeFile MoveFile(EpisodeFile episodeFile, Series series, string dest
if (!_diskProvider.FolderExists(directoryName))
{
_diskProvider.CreateFolder(directoryName);
try
{
_diskProvider.CreateFolder(directoryName);
}
catch (IOException ex)
{
_logger.ErrorException("Unable to create directory: " + directoryName, ex);
}
SetFolderPermissions(directoryName);
if (!directoryName.PathEquals(series.Path))