check for app updates less frequently

This commit is contained in:
Luke Pulverenti 2013-08-16 14:43:11 -04:00
parent 33eb6bca88
commit 7c0f97d56b
4 changed files with 57 additions and 22 deletions

View file

@ -557,14 +557,59 @@ namespace MediaBrowser.Common.Implementations
/// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
public abstract bool CanSelfUpdate { get; }
private Tuple<CheckForUpdateResult, DateTime> _lastUpdateCheckResult;
/// <summary>
/// Checks for update.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress.</param>
/// <returns>Task{CheckForUpdateResult}.</returns>
public abstract Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken,
IProgress<double> progress);
public async Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken,
IProgress<double> progress)
{
if (_lastUpdateCheckResult != null)
{
// Let dev users get results more often for testing purposes
var cacheLength = ConfigurationManager.CommonConfiguration.SystemUpdateLevel == PackageVersionClass.Dev
? TimeSpan.FromHours(1)
: TimeSpan.FromHours(12);
if ((DateTime.UtcNow - _lastUpdateCheckResult.Item2) < cacheLength)
{
return _lastUpdateCheckResult.Item1;
}
}
var result = await CheckForApplicationUpdateInternal(cancellationToken, progress).ConfigureAwait(false);
_lastUpdateCheckResult = new Tuple<CheckForUpdateResult, DateTime>(result, DateTime.UtcNow);
return _lastUpdateCheckResult.Item1;
}
/// <summary>
/// Checks for application update internal.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress.</param>
/// <returns>Task{CheckForUpdateResult}.</returns>
private async Task<CheckForUpdateResult> CheckForApplicationUpdateInternal(CancellationToken cancellationToken,
IProgress<double> progress)
{
var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(CancellationToken.None).ConfigureAwait(false);
var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, ApplicationUpdatePackageName, ConfigurationManager.CommonConfiguration.SystemUpdateLevel);
return version != null ? new CheckForUpdateResult { AvailableVersion = version.version, IsUpdateAvailable = version.version > ApplicationVersion, Package = version } :
new CheckForUpdateResult { AvailableVersion = ApplicationVersion, IsUpdateAvailable = false };
}
/// <summary>
/// Gets the name of the application update package.
/// </summary>
/// <value>The name of the application update package.</value>
protected abstract string ApplicationUpdatePackageName { get; }
/// <summary>
/// Updates the application.

View file

@ -50,11 +50,11 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
{
return new ITaskTrigger[] {
// 1am
new DailyTrigger { TimeOfDay = TimeSpan.FromHours(1) },
// At startup
new StartupTrigger (),
// Every three hours
new IntervalTrigger { Interval = TimeSpan.FromHours(3)}
// Every so often
new IntervalTrigger { Interval = TimeSpan.FromHours(24)}
};
}

View file

@ -42,12 +42,11 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
{
return new ITaskTrigger[] {
// 1:30am
new DailyTrigger { TimeOfDay = TimeSpan.FromHours(1.5) },
// At startup
new StartupTrigger (),
new IntervalTrigger { Interval = TimeSpan.FromHours(3)},
new StartupTrigger()
// Every so often
new IntervalTrigger { Interval = TimeSpan.FromHours(24)}
};
}

View file

@ -7,7 +7,6 @@ using MediaBrowser.Common.Implementations;
using MediaBrowser.Common.Implementations.IO;
using MediaBrowser.Common.Implementations.ScheduledTasks;
using MediaBrowser.Common.Implementations.Updates;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.MediaInfo;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
@ -25,11 +24,9 @@ using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Controller.Session;
using MediaBrowser.Controller.Sorting;
using MediaBrowser.IsoMounter;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.System;
using MediaBrowser.Model.Updates;
using MediaBrowser.Providers;
using MediaBrowser.Server.Implementations;
using MediaBrowser.Server.Implementations.BdInfo;
@ -53,7 +50,6 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.ServerApplication
@ -652,14 +648,9 @@ namespace MediaBrowser.ServerApplication
}
}
public override async Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress<double> progress)
protected override string ApplicationUpdatePackageName
{
var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(CancellationToken.None).ConfigureAwait(false);
var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, Constants.MbServerPkgName, ConfigurationManager.CommonConfiguration.SystemUpdateLevel);
return version != null ? new CheckForUpdateResult { AvailableVersion = version.version, IsUpdateAvailable = version.version > ApplicationVersion, Package = version } :
new CheckForUpdateResult { AvailableVersion = ApplicationVersion, IsUpdateAvailable = false };
get { return Constants.MbServerPkgName; }
}
}
}