Revert "Switch to Parallel.ForEach for list processing with MaxParallelism"

This reverts commit 0f93e04186.
pull/9079/head
Bogdan 1 year ago
parent 429217d1d4
commit 8e80c85f03

@ -4,6 +4,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using NLog; using NLog;
using NzbDrone.Common.Instrumentation.Extensions; using NzbDrone.Common.Instrumentation.Extensions;
using NzbDrone.Common.TPL;
using NzbDrone.Core.ImportLists.ImportListMovies; using NzbDrone.Core.ImportLists.ImportListMovies;
using NzbDrone.Core.MetadataSource; using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.Movies; using NzbDrone.Core.Movies;
@ -22,6 +23,7 @@ namespace NzbDrone.Core.ImportLists
private readonly IImportListStatusService _importListStatusService; private readonly IImportListStatusService _importListStatusService;
private readonly IImportListMovieService _listMovieService; private readonly IImportListMovieService _listMovieService;
private readonly ISearchForNewMovie _movieSearch; private readonly ISearchForNewMovie _movieSearch;
private readonly IProvideMovieInfo _movieInfoService;
private readonly IMovieMetadataService _movieMetadataService; private readonly IMovieMetadataService _movieMetadataService;
private readonly Logger _logger; private readonly Logger _logger;
@ -29,6 +31,7 @@ namespace NzbDrone.Core.ImportLists
IImportListStatusService importListStatusService, IImportListStatusService importListStatusService,
IImportListMovieService listMovieService, IImportListMovieService listMovieService,
ISearchForNewMovie movieSearch, ISearchForNewMovie movieSearch,
IProvideMovieInfo movieInfoService,
IMovieMetadataService movieMetadataService, IMovieMetadataService movieMetadataService,
Logger logger) Logger logger)
{ {
@ -36,6 +39,7 @@ namespace NzbDrone.Core.ImportLists
_importListStatusService = importListStatusService; _importListStatusService = importListStatusService;
_listMovieService = listMovieService; _listMovieService = listMovieService;
_movieSearch = movieSearch; _movieSearch = movieSearch;
_movieInfoService = movieInfoService;
_movieMetadataService = movieMetadataService; _movieMetadataService = movieMetadataService;
_logger = logger; _logger = logger;
} }
@ -54,7 +58,10 @@ namespace NzbDrone.Core.ImportLists
_logger.Debug("Available import lists {0}", importLists.Count); _logger.Debug("Available import lists {0}", importLists.Count);
Parallel.ForEach(importLists, new ParallelOptions { MaxDegreeOfParallelism = 5 }, importList => var taskList = new List<Task>();
var taskFactory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.None);
foreach (var importList in importLists)
{ {
var importListLocal = importList; var importListLocal = importList;
var importListStatus = _importListStatusService.GetLastSyncListInfo(importListLocal.Definition.Id); var importListStatus = _importListStatusService.GetLastSyncListInfo(importListLocal.Definition.Id);
@ -67,7 +74,7 @@ namespace NzbDrone.Core.ImportLists
{ {
_logger.Trace("Skipping refresh of Import List {0} ({1}) due to minimum refresh interval. Next Sync after {2}", importList.Name, importListLocal.Definition.Name, importListNextSync); _logger.Trace("Skipping refresh of Import List {0} ({1}) due to minimum refresh interval. Next Sync after {2}", importList.Name, importListLocal.Definition.Name, importListNextSync);
return; continue;
} }
} }
@ -79,9 +86,11 @@ namespace NzbDrone.Core.ImportLists
{ {
_logger.Debug("Temporarily ignoring Import List {0} ({1}) till {2} due to recent failures.", importList.Name, importListLocal.Definition.Name, blockedListStatus.DisabledTill.Value.ToLocalTime()); _logger.Debug("Temporarily ignoring Import List {0} ({1}) till {2} due to recent failures.", importList.Name, importListLocal.Definition.Name, blockedListStatus.DisabledTill.Value.ToLocalTime());
result.AnyFailure |= true; // Ensure we don't clean if a list is down result.AnyFailure |= true; // Ensure we don't clean if a list is down
return; continue;
} }
var task = taskFactory.StartNew(() =>
{
try try
{ {
var importListReports = importListLocal.Fetch(); var importListReports = importListLocal.Fetch();
@ -113,7 +122,12 @@ namespace NzbDrone.Core.ImportLists
{ {
_logger.Error(e, "Error during Import List Sync of {0} ({1})", importList.Name, importListLocal.Definition.Name); _logger.Error(e, "Error during Import List Sync of {0} ({1})", importList.Name, importListLocal.Definition.Name);
} }
}); }).LogExceptions();
taskList.Add(task);
}
Task.WaitAll(taskList.ToArray());
result.Movies = result.Movies.DistinctBy(r => new { r.TmdbId, r.ImdbId, r.Title }).ToList(); result.Movies = result.Movies.DistinctBy(r => new { r.TmdbId, r.ImdbId, r.Title }).ToList();

Loading…
Cancel
Save