From 0b2c5fe6f44259af0b573073a26c5eb1c6b821d1 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 3 Sep 2015 21:34:57 -0400 Subject: [PATCH] fix scheduled task crash --- .../ScheduledTasks/TaskManager.cs | 22 +++++++++++++++---- MediaBrowser.Controller/Entities/BaseItem.cs | 4 ++++ .../LiveTv/EmbyTV/EmbyTV.cs | 21 ++++++++++++------ 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs index de7987bd2..7034113d7 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs @@ -106,9 +106,16 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks public void QueueScheduledTask(TaskExecutionOptions options) where T : IScheduledTask { - var scheduledTask = ScheduledTasks.First(t => t.ScheduledTask.GetType() == typeof(T)); + var scheduledTask = ScheduledTasks.FirstOrDefault(t => t.ScheduledTask.GetType() == typeof(T)); - QueueScheduledTask(scheduledTask, options); + if (scheduledTask == null) + { + Logger.Error("Unable to find scheduled task of type {0} in QueueScheduledTask.", typeof(T).Name); + } + else + { + QueueScheduledTask(scheduledTask, options); + } } public void QueueScheduledTask() @@ -124,9 +131,16 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks /// The task options. public void QueueScheduledTask(IScheduledTask task, TaskExecutionOptions options) { - var scheduledTask = ScheduledTasks.First(t => t.ScheduledTask.GetType() == task.GetType()); + var scheduledTask = ScheduledTasks.FirstOrDefault(t => t.ScheduledTask.GetType() == task.GetType()); - QueueScheduledTask(scheduledTask, options); + if (scheduledTask == null) + { + Logger.Error("Unable to find scheduled task of type {0} in QueueScheduledTask.", task.GetType().Name); + } + else + { + QueueScheduledTask(scheduledTask, options); + } } /// diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index d9d334ff2..f74a8bda7 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -500,6 +500,10 @@ namespace MediaBrowser.Controller.Entities return null; } + set + { + + } } public void SetParent(Folder parent) diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index 66ef20928..1786d14e4 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -618,6 +618,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV _logger.ErrorException("Error recording", ex); recording.Status = RecordingStatus.Error; } + finally + { + CancellationTokenSource removed; + _activeRecordings.TryRemove(timer.Id, out removed); + } recording.DateLastUpdated = DateTime.UtcNow; _recordingProvider.Update(recording); @@ -627,15 +632,17 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV OnSuccessfulRecording(recording); _timerProvider.Delete(timer); } + else if (DateTime.UtcNow < timer.EndDate) + { + const int retryIntervalSeconds = 60; + _logger.Info("Retrying recording in {0} seconds.", retryIntervalSeconds); + + _timerProvider.StartTimer(timer, TimeSpan.FromSeconds(retryIntervalSeconds)); + } else { - if (DateTime.UtcNow < timer.EndDate) - { - const int retryIntervalSeconds = 60; - _logger.Info("Retrying recording in {0} seconds.", retryIntervalSeconds); - - _timerProvider.StartTimer(timer, TimeSpan.FromSeconds(retryIntervalSeconds)); - } + _timerProvider.Delete(timer); + _recordingProvider.Delete(recording); } }