mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-19 07:52:33 +02:00
Fixed: Exception thrown when marking download as complete
Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
This commit is contained in:
parent
566fa8b132
commit
2328b384e2
@ -56,6 +56,10 @@ public void Setup()
|
|||||||
Mocker.GetMock<IParsingService>()
|
Mocker.GetMock<IParsingService>()
|
||||||
.Setup(s => s.GetMovie("Drone.1998"))
|
.Setup(s => s.GetMovie("Drone.1998"))
|
||||||
.Returns(remoteMovie.Movie);
|
.Returns(remoteMovie.Movie);
|
||||||
|
|
||||||
|
Mocker.GetMock<IHistoryService>()
|
||||||
|
.Setup(s => s.FindByDownloadId(It.IsAny<string>()))
|
||||||
|
.Returns(new List<MovieHistory>());
|
||||||
}
|
}
|
||||||
|
|
||||||
private RemoteMovie BuildRemoteMovie()
|
private RemoteMovie BuildRemoteMovie()
|
||||||
|
@ -2,8 +2,10 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using NLog.Fluent;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Common.Instrumentation.Extensions;
|
||||||
using NzbDrone.Core.Download.TrackedDownloads;
|
using NzbDrone.Core.Download.TrackedDownloads;
|
||||||
using NzbDrone.Core.History;
|
using NzbDrone.Core.History;
|
||||||
using NzbDrone.Core.MediaFiles;
|
using NzbDrone.Core.MediaFiles;
|
||||||
@ -150,21 +152,33 @@ public bool VerifyImport(TrackedDownload trackedDownload, List<ImportResult> imp
|
|||||||
// Double check if all movies were imported by checking the history if at least one
|
// Double check if all movies were imported by checking the history if at least one
|
||||||
// file was imported. This will allow the decision engine to reject already imported
|
// file was imported. This will allow the decision engine to reject already imported
|
||||||
// episode files and still mark the download complete when all files are imported.
|
// episode files and still mark the download complete when all files are imported.
|
||||||
if (importResults.Any(c => c.Result == ImportResultType.Imported))
|
var atLeastOneMovieImported = importResults.Any(c => c.Result == ImportResultType.Imported);
|
||||||
{
|
|
||||||
var historyItems = _historyService.FindByDownloadId(trackedDownload.DownloadItem.DownloadId)
|
var historyItems = _historyService.FindByDownloadId(trackedDownload.DownloadItem.DownloadId)
|
||||||
.OrderByDescending(h => h.Date)
|
.OrderByDescending(h => h.Date)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var allMoviesImportedInHistory = _trackedDownloadAlreadyImported.IsImported(trackedDownload, historyItems);
|
var allMoviesImportedInHistory = _trackedDownloadAlreadyImported.IsImported(trackedDownload, historyItems);
|
||||||
|
|
||||||
if (allMoviesImportedInHistory)
|
if (allMoviesImportedInHistory)
|
||||||
|
{
|
||||||
|
if (atLeastOneMovieImported)
|
||||||
{
|
{
|
||||||
_logger.Debug("All movies were imported in history for {0}", trackedDownload.DownloadItem.Title);
|
_logger.Debug("All movies were imported in history for {0}", trackedDownload.DownloadItem.Title);
|
||||||
trackedDownload.State = TrackedDownloadState.Imported;
|
trackedDownload.State = TrackedDownloadState.Imported;
|
||||||
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, trackedDownload.RemoteMovie.Movie.Id));
|
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, trackedDownload.RemoteMovie.Movie.Id));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_logger.Debug()
|
||||||
|
.Message("No Movies were just imported, but all movies were previously imported, possible issue with download history.")
|
||||||
|
.Property("MovieId", trackedDownload.RemoteMovie.Movie.Id)
|
||||||
|
.Property("DownloadId", trackedDownload.DownloadItem.DownloadId)
|
||||||
|
.Property("Title", trackedDownload.DownloadItem.Title)
|
||||||
|
.Property("Path", trackedDownload.DownloadItem.OutputPath.ToString())
|
||||||
|
.WriteSentryWarn("DownloadHistoryIncomplete")
|
||||||
|
.Write();
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.Debug("Not all movies have been imported for {0}", trackedDownload.DownloadItem.Title);
|
_logger.Debug("Not all movies have been imported for {0}", trackedDownload.DownloadItem.Title);
|
||||||
|
@ -137,7 +137,7 @@ public void Handle(MovieImportedEvent message)
|
|||||||
var history = new DownloadHistory
|
var history = new DownloadHistory
|
||||||
{
|
{
|
||||||
EventType = DownloadHistoryEventType.FileImported,
|
EventType = DownloadHistoryEventType.FileImported,
|
||||||
MovieId = message.MovieInfo.Movie.Id,
|
MovieId = message.ImportedMovie.MovieId,
|
||||||
DownloadId = downloadId,
|
DownloadId = downloadId,
|
||||||
SourceTitle = message.MovieInfo.Path,
|
SourceTitle = message.MovieInfo.Path,
|
||||||
Date = DateTime.UtcNow,
|
Date = DateTime.UtcNow,
|
||||||
@ -153,19 +153,21 @@ public void Handle(MovieImportedEvent message)
|
|||||||
|
|
||||||
public void Handle(DownloadCompletedEvent message)
|
public void Handle(DownloadCompletedEvent message)
|
||||||
{
|
{
|
||||||
|
var downloadItem = message.TrackedDownload.DownloadItem;
|
||||||
|
|
||||||
var history = new DownloadHistory
|
var history = new DownloadHistory
|
||||||
{
|
{
|
||||||
EventType = DownloadHistoryEventType.DownloadImported,
|
EventType = DownloadHistoryEventType.DownloadImported,
|
||||||
MovieId = message.MovieId,
|
MovieId = message.MovieId,
|
||||||
DownloadId = message.TrackedDownload.DownloadItem.DownloadId,
|
DownloadId = downloadItem.DownloadId,
|
||||||
SourceTitle = message.TrackedDownload.DownloadItem.OutputPath.ToString(),
|
SourceTitle = downloadItem.OutputPath.ToString(),
|
||||||
Date = DateTime.UtcNow,
|
Date = DateTime.UtcNow,
|
||||||
Protocol = message.TrackedDownload.Protocol,
|
Protocol = message.TrackedDownload.Protocol,
|
||||||
DownloadClientId = message.TrackedDownload.DownloadClient
|
DownloadClientId = message.TrackedDownload.DownloadClient
|
||||||
};
|
};
|
||||||
|
|
||||||
history.Data.Add("DownloadClient", message.TrackedDownload.DownloadItem.DownloadClientInfo.Type);
|
history.Data.Add("DownloadClient", downloadItem.DownloadClientInfo.Type);
|
||||||
history.Data.Add("DownloadClientName", message.TrackedDownload.DownloadItem.DownloadClientInfo.Name);
|
history.Data.Add("DownloadClientName", downloadItem.DownloadClientInfo.Name);
|
||||||
|
|
||||||
_repository.Insert(history);
|
_repository.Insert(history);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user