< Summary - Jellyfin

Information
Class: Emby.Server.Implementations.ScheduledTasks.Tasks.PluginUpdateTask
Assembly: Emby.Server.Implementations
File(s): /srv/git/jellyfin/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs
Line coverage
63%
Covered lines: 7
Uncovered lines: 4
Coverable lines: 11
Total lines: 120
Line coverage: 63.6%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Name()100%11100%
get_Description()100%210%
get_Category()100%210%
get_Key()100%11100%
get_IsHidden()100%210%
get_IsEnabled()100%11100%
get_IsLogged()100%210%

File(s)

/srv/git/jellyfin/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.IO;
 4using System.Linq;
 5using System.Net.Http;
 6using System.Threading;
 7using System.Threading.Tasks;
 8using MediaBrowser.Common.Updates;
 9using MediaBrowser.Model.Globalization;
 10using MediaBrowser.Model.Tasks;
 11using Microsoft.Extensions.Logging;
 12
 13namespace Emby.Server.Implementations.ScheduledTasks.Tasks
 14{
 15    /// <summary>
 16    /// Plugin Update Task.
 17    /// </summary>
 18    public class PluginUpdateTask : IScheduledTask, IConfigurableScheduledTask
 19    {
 20        private readonly ILogger<PluginUpdateTask> _logger;
 21
 22        private readonly IInstallationManager _installationManager;
 23        private readonly ILocalizationManager _localization;
 24
 25        /// <summary>
 26        /// Initializes a new instance of the <see cref="PluginUpdateTask" /> class.
 27        /// </summary>
 28        /// <param name="logger">Instance of the <see cref="ILogger"/> interface.</param>
 29        /// <param name="installationManager">Instance of the <see cref="IInstallationManager"/> interface.</param>
 30        /// <param name="localization">Instance of the <see cref="ILocalizationManager"/> interface.</param>
 31        public PluginUpdateTask(ILogger<PluginUpdateTask> logger, IInstallationManager installationManager, ILocalizatio
 32        {
 2233            _logger = logger;
 2234            _installationManager = installationManager;
 2235            _localization = localization;
 2236        }
 37
 38        /// <inheritdoc />
 4939        public string Name => _localization.GetLocalizedString("TaskUpdatePlugins");
 40
 41        /// <inheritdoc />
 042        public string Description => _localization.GetLocalizedString("TaskUpdatePluginsDescription");
 43
 44        /// <inheritdoc />
 045        public string Category => _localization.GetLocalizedString("TasksApplicationCategory");
 46
 47        /// <inheritdoc />
 148        public string Key => "PluginUpdates";
 49
 50        /// <inheritdoc />
 051        public bool IsHidden => false;
 52
 53        /// <inheritdoc />
 154        public bool IsEnabled => true;
 55
 56        /// <inheritdoc />
 057        public bool IsLogged => true;
 58
 59        /// <inheritdoc />
 60        public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
 61        {
 62            // At startup
 63            yield return new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerStartup };
 64
 65            // Every so often
 66            yield return new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHour
 67        }
 68
 69        /// <inheritdoc />
 70        public async Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
 71        {
 72            progress.Report(0);
 73
 74            var packageFetchTask = _installationManager.GetAvailablePluginUpdates(cancellationToken);
 75            var packagesToInstall = (await packageFetchTask.ConfigureAwait(false)).ToList();
 76
 77            progress.Report(10);
 78
 79            var numComplete = 0;
 80
 81            foreach (var package in packagesToInstall)
 82            {
 83                cancellationToken.ThrowIfCancellationRequested();
 84
 85                try
 86                {
 87                    await _installationManager.InstallPackage(package, cancellationToken).ConfigureAwait(false);
 88                }
 89                catch (OperationCanceledException)
 90                {
 91                    // InstallPackage has it's own inner cancellation token, so only throw this if it's ours
 92                    if (cancellationToken.IsCancellationRequested)
 93                    {
 94                        throw;
 95                    }
 96                }
 97                catch (HttpRequestException ex)
 98                {
 99                    _logger.LogError(ex, "Error downloading {0}", package.Name);
 100                }
 101                catch (IOException ex)
 102                {
 103                    _logger.LogError(ex, "Error updating {0}", package.Name);
 104                }
 105                catch (InvalidDataException ex)
 106                {
 107                    _logger.LogError(ex, "Error updating {0}", package.Name);
 108                }
 109
 110                // Update progress
 111                lock (progress)
 112                {
 113                    progress.Report((90.0 * ++numComplete / packagesToInstall.Count) + 10);
 114                }
 115            }
 116
 117            progress.Report(100);
 118        }
 119    }
 120}