From 07072d9f7bf269926a4d7aad580e2e78c444a2cd Mon Sep 17 00:00:00 2001 From: dkanada Date: Thu, 31 Jan 2019 15:12:18 +0900 Subject: move all scheduled tasks and triggers into folders --- .../ScheduledTasks/Tasks/PluginUpdateTask.cs | 142 +++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs (limited to 'Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs') diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs new file mode 100644 index 000000000..62533a017 --- /dev/null +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs @@ -0,0 +1,142 @@ +using MediaBrowser.Common; +using MediaBrowser.Common.Updates; +using MediaBrowser.Model.Net; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Common.Progress; +using MediaBrowser.Model.Tasks; +using Microsoft.Extensions.Logging; + +namespace Emby.Server.Implementations.ScheduledTasks +{ + /// + /// Plugin Update Task + /// + public class PluginUpdateTask : IScheduledTask, IConfigurableScheduledTask + { + /// + /// The _logger + /// + private readonly ILogger _logger; + + private readonly IInstallationManager _installationManager; + + private readonly IApplicationHost _appHost; + + public PluginUpdateTask(ILogger logger, IInstallationManager installationManager, IApplicationHost appHost) + { + _logger = logger; + _installationManager = installationManager; + _appHost = appHost; + } + + /// + /// Creates the triggers that define when the task will run + /// + /// IEnumerable{BaseTaskTrigger}. + public IEnumerable GetDefaultTriggers() + { + return new[] { + + // At startup + new TaskTriggerInfo {Type = TaskTriggerInfo.TriggerStartup}, + + // Every so often + new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(24).Ticks} + }; + } + + public string Key + { + get { return "PluginUpdates"; } + } + + /// + /// Update installed plugins + /// + /// The cancellation token. + /// The progress. + /// Task. + public async Task Execute(CancellationToken cancellationToken, IProgress progress) + { + progress.Report(0); + + var packagesToInstall = (await _installationManager.GetAvailablePluginUpdates(typeof(PluginUpdateTask).Assembly.GetName().Version, true, cancellationToken).ConfigureAwait(false)).ToList(); + + progress.Report(10); + + var numComplete = 0; + + foreach (var package in packagesToInstall) + { + cancellationToken.ThrowIfCancellationRequested(); + + try + { + await _installationManager.InstallPackage(package, true, new SimpleProgress(), cancellationToken).ConfigureAwait(false); + } + catch (OperationCanceledException) + { + // InstallPackage has it's own inner cancellation token, so only throw this if it's ours + if (cancellationToken.IsCancellationRequested) + { + throw; + } + } + catch (HttpException ex) + { + _logger.LogError(ex, "Error downloading {0}", package.name); + } + catch (IOException ex) + { + _logger.LogError(ex, "Error updating {0}", package.name); + } + + // Update progress + lock (progress) + { + numComplete++; + double percent = numComplete; + percent /= packagesToInstall.Count; + + progress.Report(90 * percent + 10); + } + } + + progress.Report(100); + } + + /// + /// Gets the name of the task + /// + /// The name. + public string Name + { + get { return "Check for plugin updates"; } + } + + /// + /// Gets the description. + /// + /// The description. + public string Description + { + get { return "Downloads and installs updates for plugins that are configured to update automatically."; } + } + + public string Category + { + get { return "Application"; } + } + + public bool IsHidden => true; + + public bool IsEnabled => true; + + public bool IsLogged => true; + } +} -- cgit v1.2.3 From 08ca1337a92c62b68d5a901cdb372b9b6b0a6a02 Mon Sep 17 00:00:00 2001 From: dkanada Date: Thu, 31 Jan 2019 15:20:34 +0900 Subject: unhide several scheduled tasks and add missing properties --- .../ScheduledTasks/Tasks/ChapterImagesTask.cs | 10 +++++++-- .../ScheduledTasks/Tasks/DeleteCacheFileTask.cs | 6 +++--- .../ScheduledTasks/Tasks/DeleteLogFileTask.cs | 6 +++--- .../ScheduledTasks/Tasks/PeopleValidationTask.cs | 10 +++++++-- .../ScheduledTasks/Tasks/PluginUpdateTask.cs | 24 ++++++---------------- .../Tasks/RefreshMediaLibraryTask.cs | 6 ++++++ 6 files changed, 34 insertions(+), 28 deletions(-) (limited to 'Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs') diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/ChapterImagesTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/ChapterImagesTask.cs index 5373b4392..a6d43a69a 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/ChapterImagesTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/ChapterImagesTask.cs @@ -68,8 +68,6 @@ namespace Emby.Server.Implementations.ScheduledTasks }; } - public string Key => "RefreshChapterImages"; - /// /// Returns the task to be executed /// @@ -178,5 +176,13 @@ namespace Emby.Server.Implementations.ScheduledTasks /// /// The category. public string Category => "Library"; + + public string Key => "RefreshChapterImages"; + + public bool IsHidden => false; + + public bool IsEnabled => true; + + public bool IsLogged => true; } } diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs index 52077b242..fc9d57e0b 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs @@ -164,8 +164,6 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks /// The name. public string Name => "Cache file cleanup"; - public string Key => "DeleteCacheFiles"; - /// /// Gets the description. /// @@ -178,11 +176,13 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks /// The category. public string Category => "Maintenance"; + public string Key => "DeleteCacheFiles"; + /// /// Gets a value indicating whether this instance is hidden. /// /// true if this instance is hidden; otherwise, false. - public bool IsHidden => true; + public bool IsHidden => false; public bool IsEnabled => true; diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs index a57fe4945..ddb74ef3e 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs @@ -81,8 +81,6 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks return Task.CompletedTask; } - public string Key => "CleanLogFiles"; - /// /// Gets the name of the task /// @@ -101,11 +99,13 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks /// The category. public string Category => "Maintenance"; + public string Key => "CleanLogFiles"; + /// /// Gets a value indicating whether this instance is hidden. /// /// true if this instance is hidden; otherwise, false. - public bool IsHidden => true; + public bool IsHidden => false; public bool IsEnabled => true; diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/PeopleValidationTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/PeopleValidationTask.cs index 68031170f..ebdc6a13e 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/PeopleValidationTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/PeopleValidationTask.cs @@ -47,8 +47,6 @@ namespace Emby.Server.Implementations.ScheduledTasks }; } - public string Key => "RefreshPeople"; - /// /// Returns the task to be executed /// @@ -77,5 +75,13 @@ namespace Emby.Server.Implementations.ScheduledTasks /// /// The category. public string Category => "Library"; + + public string Key => "RefreshPeople"; + + public bool IsHidden => false; + + public bool IsEnabled => true; + + public bool IsLogged => true; } } diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs index 62533a017..8e27b0eb8 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs @@ -50,11 +50,6 @@ namespace Emby.Server.Implementations.ScheduledTasks }; } - public string Key - { - get { return "PluginUpdates"; } - } - /// /// Update installed plugins /// @@ -114,26 +109,19 @@ namespace Emby.Server.Implementations.ScheduledTasks /// Gets the name of the task /// /// The name. - public string Name - { - get { return "Check for plugin updates"; } - } + public string Name => "Check for plugin updates"; /// /// Gets the description. /// /// The description. - public string Description - { - get { return "Downloads and installs updates for plugins that are configured to update automatically."; } - } + public string Description => "Downloads and installs updates for plugins that are configured to update automatically."; - public string Category - { - get { return "Application"; } - } + public string Category => "Application"; + + public string Key => "PluginUpdates"; - public bool IsHidden => true; + public bool IsHidden => false; public bool IsEnabled => true; diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/RefreshMediaLibraryTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/RefreshMediaLibraryTask.cs index f6fa64d13..618efd732 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/RefreshMediaLibraryTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/RefreshMediaLibraryTask.cs @@ -77,5 +77,11 @@ namespace Emby.Server.Implementations.ScheduledTasks public string Category => "Library"; public string Key => "RefreshLibrary"; + + public bool IsHidden => false; + + public bool IsEnabled => true; + + public bool IsLogged => true; } } -- cgit v1.2.3 From aadf7676d1d52b67272d5201ccc9835d02a77c0e Mon Sep 17 00:00:00 2001 From: dkanada Date: Thu, 31 Jan 2019 15:23:34 +0900 Subject: remove useless comments --- .../ScheduledTasks/Tasks/ChapterImagesTask.cs | 12 ------------ .../ScheduledTasks/Tasks/DeleteCacheFileTask.cs | 16 ---------------- .../ScheduledTasks/Tasks/DeleteLogFileTask.cs | 16 ---------------- .../ScheduledTasks/Tasks/PeopleValidationTask.cs | 12 ------------ .../ScheduledTasks/Tasks/PluginUpdateTask.cs | 8 -------- .../ScheduledTasks/Tasks/RefreshMediaLibraryTask.cs | 12 ------------ 6 files changed, 76 deletions(-) (limited to 'Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs') diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/ChapterImagesTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/ChapterImagesTask.cs index a6d43a69a..81fdb96d2 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/ChapterImagesTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/ChapterImagesTask.cs @@ -159,22 +159,10 @@ namespace Emby.Server.Implementations.ScheduledTasks } } - /// - /// Gets the name of the task - /// - /// The name. public string Name => "Chapter image extraction"; - /// - /// Gets the description. - /// - /// The description. public string Description => "Creates thumbnails for videos that have chapters."; - /// - /// Gets the category. - /// - /// The category. public string Category => "Library"; public string Key => "RefreshChapterImages"; diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs index fc9d57e0b..6ec83b5c0 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs @@ -158,30 +158,14 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks } } - /// - /// Gets the name of the task - /// - /// The name. public string Name => "Cache file cleanup"; - /// - /// Gets the description. - /// - /// The description. public string Description => "Deletes cache files no longer needed by the system"; - /// - /// Gets the category. - /// - /// The category. public string Category => "Maintenance"; public string Key => "DeleteCacheFiles"; - /// - /// Gets a value indicating whether this instance is hidden. - /// - /// true if this instance is hidden; otherwise, false. public bool IsHidden => false; public bool IsEnabled => true; diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs index ddb74ef3e..e468c301a 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs @@ -81,30 +81,14 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks return Task.CompletedTask; } - /// - /// Gets the name of the task - /// - /// The name. public string Name => "Log file cleanup"; - /// - /// Gets the description. - /// - /// The description. public string Description => string.Format("Deletes log files that are more than {0} days old.", ConfigurationManager.CommonConfiguration.LogFileRetentionDays); - /// - /// Gets the category. - /// - /// The category. public string Category => "Maintenance"; public string Key => "CleanLogFiles"; - /// - /// Gets a value indicating whether this instance is hidden. - /// - /// true if this instance is hidden; otherwise, false. public bool IsHidden => false; public bool IsEnabled => true; diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/PeopleValidationTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/PeopleValidationTask.cs index ebdc6a13e..d70799c47 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/PeopleValidationTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/PeopleValidationTask.cs @@ -58,22 +58,10 @@ namespace Emby.Server.Implementations.ScheduledTasks return _libraryManager.ValidatePeople(cancellationToken, progress); } - /// - /// Gets the name of the task - /// - /// The name. public string Name => "Refresh people"; - /// - /// Gets the description. - /// - /// The description. public string Description => "Updates metadata for actors and directors in your media library."; - /// - /// Gets the category. - /// - /// The category. public string Category => "Library"; public string Key => "RefreshPeople"; diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs index 8e27b0eb8..798dfb2ae 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs @@ -105,16 +105,8 @@ namespace Emby.Server.Implementations.ScheduledTasks progress.Report(100); } - /// - /// Gets the name of the task - /// - /// The name. public string Name => "Check for plugin updates"; - /// - /// Gets the description. - /// - /// The description. public string Description => "Downloads and installs updates for plugins that are configured to update automatically."; public string Category => "Application"; diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/RefreshMediaLibraryTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/RefreshMediaLibraryTask.cs index 618efd732..1a3d85ad7 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/RefreshMediaLibraryTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/RefreshMediaLibraryTask.cs @@ -58,22 +58,10 @@ namespace Emby.Server.Implementations.ScheduledTasks return ((LibraryManager)_libraryManager).ValidateMediaLibraryInternal(progress, cancellationToken); } - /// - /// Gets the name. - /// - /// The name. public string Name => "Scan media library"; - /// - /// Gets the description. - /// - /// The description. public string Description => "Scans your media library and refreshes metatata based on configuration."; - /// - /// Gets the category. - /// - /// The category. public string Category => "Library"; public string Key => "RefreshLibrary"; -- cgit v1.2.3 From 52e91243e5e50bf42a7deb234365a1edd84649d1 Mon Sep 17 00:00:00 2001 From: dkanada Date: Thu, 31 Jan 2019 15:33:39 +0900 Subject: merge progress calculation into a single line --- Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs') diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs index 798dfb2ae..dc3bebe9e 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs @@ -95,10 +95,7 @@ namespace Emby.Server.Implementations.ScheduledTasks lock (progress) { numComplete++; - double percent = numComplete; - percent /= packagesToInstall.Count; - - progress.Report(90 * percent + 10); + progress.Report(90 * numComplete / packagesToInstall.Count + 10); } } -- cgit v1.2.3 From c118f111b6eb4d0f665886f294114071ebe051a6 Mon Sep 17 00:00:00 2001 From: dkanada Date: Fri, 1 Feb 2019 14:45:43 +0900 Subject: add suggestions from code review --- Emby.Server.Implementations/Emby.Server.Implementations.csproj | 3 --- Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) (limited to 'Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs') diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csproj index daad6f287..92e3172f1 100644 --- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj +++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj @@ -46,7 +46,4 @@ - - - diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs index dc3bebe9e..c6431c311 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs @@ -95,7 +95,7 @@ namespace Emby.Server.Implementations.ScheduledTasks lock (progress) { numComplete++; - progress.Report(90 * numComplete / packagesToInstall.Count + 10); + progress.Report(90.0 * numComplete / packagesToInstall.Count + 10); } } -- cgit v1.2.3