mirror of
https://github.com/Sonarr/Sonarr.git
synced 2025-01-29 11:23:02 +02:00
Fixed: A season pack import taking a long time should no longer cause the download to be deleted prematurely.
This commit is contained in:
parent
95bd82778f
commit
d0bf539a73
@ -40,7 +40,7 @@ namespace NzbDrone.Common.Test.TPLTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void should_throttle_cals()
|
public void should_throttle_calls()
|
||||||
{
|
{
|
||||||
var counter = new Counter();
|
var counter = new Counter();
|
||||||
var debounceFunction = new Debouncer(counter.Hit, TimeSpan.FromMilliseconds(50));
|
var debounceFunction = new Debouncer(counter.Hit, TimeSpan.FromMilliseconds(50));
|
||||||
@ -64,6 +64,62 @@ namespace NzbDrone.Common.Test.TPLTests
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_hold_the_call_while_paused()
|
||||||
|
{
|
||||||
|
var counter = new Counter();
|
||||||
|
var debounceFunction = new Debouncer(counter.Hit, TimeSpan.FromMilliseconds(50));
|
||||||
|
|
||||||
|
debounceFunction.Pause();
|
||||||
|
|
||||||
|
debounceFunction.Execute();
|
||||||
|
debounceFunction.Execute();
|
||||||
|
|
||||||
|
Thread.Sleep(100);
|
||||||
|
|
||||||
|
counter.Count.Should().Be(0);
|
||||||
|
|
||||||
|
debounceFunction.Execute();
|
||||||
|
debounceFunction.Execute();
|
||||||
|
|
||||||
|
Thread.Sleep(100);
|
||||||
|
|
||||||
|
counter.Count.Should().Be(0);
|
||||||
|
|
||||||
|
debounceFunction.Resume();
|
||||||
|
|
||||||
|
Thread.Sleep(20);
|
||||||
|
|
||||||
|
counter.Count.Should().Be(0);
|
||||||
|
|
||||||
|
Thread.Sleep(100);
|
||||||
|
|
||||||
|
counter.Count.Should().Be(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_handle_pause_reentrancy()
|
||||||
|
{
|
||||||
|
var counter = new Counter();
|
||||||
|
var debounceFunction = new Debouncer(counter.Hit, TimeSpan.FromMilliseconds(50));
|
||||||
|
|
||||||
|
debounceFunction.Pause();
|
||||||
|
debounceFunction.Pause();
|
||||||
|
|
||||||
|
debounceFunction.Execute();
|
||||||
|
debounceFunction.Execute();
|
||||||
|
|
||||||
|
debounceFunction.Resume();
|
||||||
|
|
||||||
|
Thread.Sleep(100);
|
||||||
|
|
||||||
|
counter.Count.Should().Be(0);
|
||||||
|
|
||||||
|
debounceFunction.Resume();
|
||||||
|
|
||||||
|
Thread.Sleep(100);
|
||||||
|
|
||||||
|
counter.Count.Should().Be(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace NzbDrone.Common.TPL
|
namespace NzbDrone.Common.TPL
|
||||||
{
|
{
|
||||||
@ -7,6 +8,9 @@ namespace NzbDrone.Common.TPL
|
|||||||
private readonly Action _action;
|
private readonly Action _action;
|
||||||
private readonly System.Timers.Timer _timer;
|
private readonly System.Timers.Timer _timer;
|
||||||
|
|
||||||
|
private volatile int _paused;
|
||||||
|
private volatile bool _triggered;
|
||||||
|
|
||||||
public Debouncer(Action action, TimeSpan debounceDuration)
|
public Debouncer(Action action, TimeSpan debounceDuration)
|
||||||
{
|
{
|
||||||
_action = action;
|
_action = action;
|
||||||
@ -16,13 +20,45 @@ namespace NzbDrone.Common.TPL
|
|||||||
|
|
||||||
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (_paused == 0)
|
||||||
|
{
|
||||||
|
_triggered = false;
|
||||||
_timer.Stop();
|
_timer.Stop();
|
||||||
_action();
|
_action();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Execute()
|
public void Execute()
|
||||||
|
{
|
||||||
|
lock (_timer)
|
||||||
|
{
|
||||||
|
_triggered = true;
|
||||||
|
if (_paused == 0)
|
||||||
{
|
{
|
||||||
_timer.Start();
|
_timer.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Pause()
|
||||||
|
{
|
||||||
|
lock (_timer)
|
||||||
|
{
|
||||||
|
_paused++;
|
||||||
|
_timer.Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Resume()
|
||||||
|
{
|
||||||
|
lock (_timer)
|
||||||
|
{
|
||||||
|
_paused--;
|
||||||
|
if (_paused == 0 && _triggered)
|
||||||
|
{
|
||||||
|
_timer.Start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -12,11 +12,12 @@ using NzbDrone.Core.Messaging.Events;
|
|||||||
namespace NzbDrone.Core.Download.TrackedDownloads
|
namespace NzbDrone.Core.Download.TrackedDownloads
|
||||||
{
|
{
|
||||||
public class DownloadMonitoringService : IExecute<CheckForFinishedDownloadCommand>,
|
public class DownloadMonitoringService : IExecute<CheckForFinishedDownloadCommand>,
|
||||||
IHandleAsync<EpisodeGrabbedEvent>,
|
IHandle<EpisodeGrabbedEvent>,
|
||||||
IHandleAsync<EpisodeImportedEvent>
|
IHandle<EpisodeImportedEvent>
|
||||||
{
|
{
|
||||||
private readonly IProvideDownloadClient _downloadClientProvider;
|
private readonly IProvideDownloadClient _downloadClientProvider;
|
||||||
private readonly IEventAggregator _eventAggregator;
|
private readonly IEventAggregator _eventAggregator;
|
||||||
|
private readonly IManageCommandQueue _manageCommandQueue;
|
||||||
private readonly IConfigService _configService;
|
private readonly IConfigService _configService;
|
||||||
private readonly IFailedDownloadService _failedDownloadService;
|
private readonly IFailedDownloadService _failedDownloadService;
|
||||||
private readonly ICompletedDownloadService _completedDownloadService;
|
private readonly ICompletedDownloadService _completedDownloadService;
|
||||||
@ -26,6 +27,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads
|
|||||||
|
|
||||||
public DownloadMonitoringService(IProvideDownloadClient downloadClientProvider,
|
public DownloadMonitoringService(IProvideDownloadClient downloadClientProvider,
|
||||||
IEventAggregator eventAggregator,
|
IEventAggregator eventAggregator,
|
||||||
|
IManageCommandQueue manageCommandQueue,
|
||||||
IConfigService configService,
|
IConfigService configService,
|
||||||
IFailedDownloadService failedDownloadService,
|
IFailedDownloadService failedDownloadService,
|
||||||
ICompletedDownloadService completedDownloadService,
|
ICompletedDownloadService completedDownloadService,
|
||||||
@ -34,16 +36,25 @@ namespace NzbDrone.Core.Download.TrackedDownloads
|
|||||||
{
|
{
|
||||||
_downloadClientProvider = downloadClientProvider;
|
_downloadClientProvider = downloadClientProvider;
|
||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = eventAggregator;
|
||||||
|
_manageCommandQueue = manageCommandQueue;
|
||||||
_configService = configService;
|
_configService = configService;
|
||||||
_failedDownloadService = failedDownloadService;
|
_failedDownloadService = failedDownloadService;
|
||||||
_completedDownloadService = completedDownloadService;
|
_completedDownloadService = completedDownloadService;
|
||||||
_trackedDownloadService = trackedDownloadService;
|
_trackedDownloadService = trackedDownloadService;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
_refreshDebounce = new Debouncer(Refresh, TimeSpan.FromSeconds(5));
|
_refreshDebounce = new Debouncer(QueueRefresh, TimeSpan.FromSeconds(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void QueueRefresh()
|
||||||
|
{
|
||||||
|
_manageCommandQueue.Push(new CheckForFinishedDownloadCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Refresh()
|
private void Refresh()
|
||||||
|
{
|
||||||
|
_refreshDebounce.Pause();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var downloadClients = _downloadClientProvider.GetDownloadClients();
|
var downloadClients = _downloadClientProvider.GetDownloadClients();
|
||||||
|
|
||||||
@ -57,6 +68,11 @@ namespace NzbDrone.Core.Download.TrackedDownloads
|
|||||||
|
|
||||||
_eventAggregator.PublishEvent(new TrackedDownloadRefreshedEvent(trackedDownload));
|
_eventAggregator.PublishEvent(new TrackedDownloadRefreshedEvent(trackedDownload));
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_refreshDebounce.Resume();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<TrackedDownload> ProcessClientDownloads(IDownloadClient downloadClient)
|
private List<TrackedDownload> ProcessClientDownloads(IDownloadClient downloadClient)
|
||||||
{
|
{
|
||||||
@ -128,12 +144,12 @@ namespace NzbDrone.Core.Download.TrackedDownloads
|
|||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleAsync(EpisodeGrabbedEvent message)
|
public void Handle(EpisodeGrabbedEvent message)
|
||||||
{
|
{
|
||||||
_refreshDebounce.Execute();
|
_refreshDebounce.Execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleAsync(EpisodeImportedEvent message)
|
public void Handle(EpisodeImportedEvent message)
|
||||||
{
|
{
|
||||||
_refreshDebounce.Execute();
|
_refreshDebounce.Execute();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user