From ac68e0ba413e833ede14034cf3367e33b94b9eb3 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 8 Feb 2015 13:21:24 -0500 Subject: [PATCH] sync updates --- .../UserLibrary/PersonsService.cs | 1 - .../ScheduledTasks/ScheduledTaskWorker.cs | 72 +++++++++++++++++-- .../Library/LibraryManager.cs | 2 +- .../Localization/Server/server.json | 12 ++-- 4 files changed, 75 insertions(+), 12 deletions(-) diff --git a/MediaBrowser.Api/UserLibrary/PersonsService.cs b/MediaBrowser.Api/UserLibrary/PersonsService.cs index b424c93138..e9b3fa402f 100644 --- a/MediaBrowser.Api/UserLibrary/PersonsService.cs +++ b/MediaBrowser.Api/UserLibrary/PersonsService.cs @@ -4,7 +4,6 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Dto; -using MediaBrowser.Model.Querying; using ServiceStack; using System; using System.Collections.Generic; diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs index b09cb71055..4d6cc16089 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs @@ -335,12 +335,30 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks trigger.Start(false); } + private Task _currentTask; + /// /// Executes the task /// /// Task. /// Cannot execute a Task that is already running public async Task Execute() + { + var task = ExecuteInternal(); + + _currentTask = task; + + try + { + await task.ConfigureAwait(false); + } + finally + { + _currentTask = null; + } + } + + private async Task ExecuteInternal() { // Cancel the current execution, if any if (CurrentCancellationTokenSource != null) @@ -585,14 +603,60 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks { DisposeTriggers(); - if (State == TaskState.Running) + var wassRunning = State == TaskState.Running; + var startTime = CurrentExecutionStartTime; + + var token = CurrentCancellationTokenSource; + if (token != null) + { + try + { + Logger.Debug(Name + ": Cancelling"); + token.Cancel(); + } + catch (Exception ex) + { + Logger.ErrorException("Error calling CancellationToken.Cancel();", ex); + } + } + var task = _currentTask; + if (task != null) { - OnTaskCompleted(CurrentExecutionStartTime, DateTime.UtcNow, TaskCompletionStatus.Aborted, null); + try + { + Logger.Debug(Name + ": Waiting on Task"); + var exited = Task.WaitAll(new[] { task }, 2000); + + if (exited) + { + Logger.Debug(Name + ": Task exited"); + } + else + { + Logger.Debug(Name + ": Timed out waiting for task to stop"); + } + } + catch (Exception ex) + { + Logger.ErrorException("Error calling Task.WaitAll();", ex); + } } - if (CurrentCancellationTokenSource != null) + if (token != null) + { + try + { + Logger.Debug(Name + ": Disposing CancellationToken"); + token.Dispose(); + } + catch (Exception ex) + { + Logger.ErrorException("Error calling CancellationToken.Dispose();", ex); + } + } + if (wassRunning) { - CurrentCancellationTokenSource.Dispose(); + OnTaskCompleted(startTime, DateTime.UtcNow, TaskCompletionStatus.Aborted, null); } } } diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 29871d9284..aac4c87f54 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -1098,7 +1098,7 @@ namespace MediaBrowser.Server.Implementations.Library try { - await task.Run(innerProgress, cancellationToken); + await task.Run(innerProgress, cancellationToken).ConfigureAwait(false); } catch (OperationCanceledException) { diff --git a/MediaBrowser.Server.Implementations/Localization/Server/server.json b/MediaBrowser.Server.Implementations/Localization/Server/server.json index c280b32ea2..a75f4c83bb 100644 --- a/MediaBrowser.Server.Implementations/Localization/Server/server.json +++ b/MediaBrowser.Server.Implementations/Localization/Server/server.json @@ -285,10 +285,10 @@ "ButtonHelp": "Help", "OptionAllowUserToManageServer": "Allow this user to manage the server", "HeaderFeatureAccess": "Feature Access", - "OptionAllowMediaPlayback": "Media playback", - "OptionAllowBrowsingLiveTv": "Live TV", - "OptionAllowDeleteLibraryContent": "Media deletion", - "OptionAllowManageLiveTv": "Live TV recording management", + "OptionAllowMediaPlayback": "Allow media playback", + "OptionAllowBrowsingLiveTv": "Allow Live TV access", + "OptionAllowDeleteLibraryContent": "Allow media deletion", + "OptionAllowManageLiveTv": "Allow Live TV recording management", "OptionAllowRemoteControlOthers": "Allow remote control of other users", "OptionAllowRemoteSharedDevices": "Allow remote control of shared devices", "OptionAllowRemoteSharedDevicesHelp": "Dlna devices are considered shared until a user begins controlling it.", @@ -1362,8 +1362,8 @@ "LabelEnableSingleImageInDidlLimitHelp": "Some devices will not render properly if multiple images are embedded within Didl.", "TabActivity": "Activity", "TitleSync": "Sync", - "OptionAllowSyncContent": "Sync", - "OptionAllowContentDownloading": "Media downloading", + "OptionAllowSyncContent": "Allow Sync", + "OptionAllowContentDownloading": "Allow media downloading", "NameSeasonUnknown": "Season Unknown", "NameSeasonNumber": "Season {0}", "LabelNewUserNameHelp": "Usernames can contain letters (a-z), numbers (0-9), dashes (-), underscores (_), apostrophes ('), and periods (.)",