< 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: 124
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>
 18public 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, ILocalizationMan
 32    {
 2133        _logger = logger;
 2134        _installationManager = installationManager;
 2135        _localization = localization;
 2136    }
 37
 38    /// <inheritdoc />
 5839    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 />
 348    public string Key => "PluginUpdates";
 49
 50    /// <inheritdoc />
 051    public bool IsHidden => false;
 52
 53    /// <inheritdoc />
 254    public bool IsEnabled => true;
 55
 56    /// <inheritdoc />
 057    public bool IsLogged => true;
 58
 59    /// <inheritdoc />
 60    public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
 61    {
 62        yield return new TaskTriggerInfo
 63        {
 64            Type = TaskTriggerInfoType.StartupTrigger
 65        };
 66
 67        yield return new TaskTriggerInfo
 68        {
 69            Type = TaskTriggerInfoType.IntervalTrigger,
 70            IntervalTicks = TimeSpan.FromHours(24).Ticks
 71        };
 72    }
 73
 74    /// <inheritdoc />
 75    public async Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
 76    {
 77        progress.Report(0);
 78
 79        var packageFetchTask = _installationManager.GetAvailablePluginUpdates(cancellationToken);
 80        var packagesToInstall = (await packageFetchTask.ConfigureAwait(false)).ToList();
 81
 82        progress.Report(10);
 83
 84        var numComplete = 0;
 85
 86        foreach (var package in packagesToInstall)
 87        {
 88            cancellationToken.ThrowIfCancellationRequested();
 89
 90            try
 91            {
 92                await _installationManager.InstallPackage(package, cancellationToken).ConfigureAwait(false);
 93            }
 94            catch (OperationCanceledException)
 95            {
 96                // InstallPackage has its own inner cancellation token, so only throw this if it's ours
 97                if (cancellationToken.IsCancellationRequested)
 98                {
 99                    throw;
 100                }
 101            }
 102            catch (HttpRequestException ex)
 103            {
 104                _logger.LogError(ex, "Error downloading {Name}", package.Name);
 105            }
 106            catch (IOException ex)
 107            {
 108                _logger.LogError(ex, "Error updating {Name}", package.Name);
 109            }
 110            catch (InvalidDataException ex)
 111            {
 112                _logger.LogError(ex, "Error updating {Name}", package.Name);
 113            }
 114
 115            // Update progress
 116            lock (progress)
 117            {
 118                progress.Report((90.0 * ++numComplete / packagesToInstall.Count) + 10);
 119            }
 120        }
 121
 122        progress.Report(100);
 123    }
 124}