update upgrade process

This commit is contained in:
Luke Pulverenti 2016-02-03 15:52:45 -05:00
parent 4fc3753f64
commit fb2a320416
6 changed files with 76 additions and 12 deletions

View File

@ -453,7 +453,7 @@ namespace MediaBrowser.Common.Implementations
RegisterSingleInstance<IApplicationPaths>(ApplicationPaths);
TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, Logger, FileSystemManager);
TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, LogManager.GetLogger("TaskManager"), FileSystemManager);
RegisterSingleInstance(JsonSerializer);
RegisterSingleInstance(XmlSerializer);
@ -465,7 +465,7 @@ namespace MediaBrowser.Common.Implementations
RegisterSingleInstance(FileSystemManager);
HttpClient = new HttpClientManager.HttpClientManager(ApplicationPaths, Logger, FileSystemManager);
HttpClient = new HttpClientManager.HttpClientManager(ApplicationPaths, LogManager.GetLogger("HttpClient"), FileSystemManager);
RegisterSingleInstance(HttpClient);
NetworkManager = CreateNetworkManager(LogManager.GetLogger("NetworkManager"));
@ -474,7 +474,7 @@ namespace MediaBrowser.Common.Implementations
SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, LogManager);
RegisterSingleInstance(SecurityManager);
InstallationManager = new InstallationManager(Logger, this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, ConfigurationManager, FileSystemManager);
InstallationManager = new InstallationManager(LogManager.GetLogger("InstallationManager"), this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, ConfigurationManager, FileSystemManager);
RegisterSingleInstance(InstallationManager);
ZipClient = new ZipClient(FileSystemManager);

View File

@ -55,6 +55,25 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
private ILogger Logger { get; set; }
private readonly IFileSystem _fileSystem;
private bool _suspendTriggers;
public bool SuspendTriggers
{
get { return _suspendTriggers; }
set
{
Logger.Info("Setting SuspendTriggers to {0}", value);
var executeQueued = _suspendTriggers && !value;
_suspendTriggers = value;
if (executeQueued)
{
ExecuteQueuedTasks();
}
}
}
/// <summary>
/// Initializes a new instance of the <see cref="TaskManager" /> class.
/// </summary>
@ -151,6 +170,31 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
QueueScheduledTask<T>(new TaskExecutionOptions());
}
public void Execute<T>()
where T : IScheduledTask
{
var scheduledTask = ScheduledTasks.FirstOrDefault(t => t.ScheduledTask.GetType() == typeof(T));
if (scheduledTask == null)
{
Logger.Error("Unable to find scheduled task of type {0} in Execute.", typeof(T).Name);
}
else
{
var type = scheduledTask.ScheduledTask.GetType();
Logger.Info("Queueing task {0}", type.Name);
lock (_taskQueue)
{
if (scheduledTask.State == TaskState.Idle)
{
Execute(scheduledTask, new TaskExecutionOptions());
}
}
}
}
/// <summary>
/// Queues the scheduled task.
/// </summary>
@ -183,7 +227,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
lock (_taskQueue)
{
if (task.State == TaskState.Idle)
if (task.State == TaskState.Idle && !SuspendTriggers)
{
Execute(task, options);
return;
@ -273,6 +317,13 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
/// </summary>
private void ExecuteQueuedTasks()
{
if (SuspendTriggers)
{
return;
}
Logger.Info("ExecuteQueuedTasks");
// Execute queued tasks
lock (_taskQueue)
{

View File

@ -66,7 +66,12 @@ namespace MediaBrowser.Common.ScheduledTasks
void Cancel(IScheduledTaskWorker task);
Task Execute(IScheduledTaskWorker task, TaskExecutionOptions options = null);
void Execute<T>()
where T : IScheduledTask;
event EventHandler<GenericEventArgs<IScheduledTaskWorker>> TaskExecuting;
event EventHandler<TaskCompletionEventArgs> TaskCompleted;
bool SuspendTriggers { get; set; }
}
}

View File

@ -32,7 +32,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
private readonly ILocalizationManager _localization;
private readonly ITaskManager _taskManager;
public const int MigrationVersion = 12;
public const int MigrationVersion = 17;
public static bool EnableUnavailableMessage = false;
public CleanDatabaseScheduledTask(ILibraryManager libraryManager, IItemRepository itemRepo, ILogger logger, IServerConfigurationManager config, IFileSystem fileSystem, IHttpServer httpServer, ILocalizationManager localization, ITaskManager taskManager)
@ -97,12 +97,20 @@ namespace MediaBrowser.Server.Implementations.Persistence
await _itemRepo.UpdateInheritedValues(cancellationToken).ConfigureAwait(false);
if (_config.Configuration.MigrationVersion < MigrationVersion)
{
_config.Configuration.MigrationVersion = MigrationVersion;
_config.SaveConfiguration();
}
if (EnableUnavailableMessage)
{
EnableUnavailableMessage = false;
_httpServer.GlobalResponse = null;
_taskManager.QueueScheduledTask<RefreshMediaLibraryTask>();
}
_taskManager.SuspendTriggers = false;
}
private void OnProgress(double newPercentCommplete)
@ -164,12 +172,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
progress.Report(percent * 100);
}
if (_config.Configuration.MigrationVersion < MigrationVersion)
{
_config.Configuration.MigrationVersion = MigrationVersion;
_config.SaveConfiguration();
}
progress.Report(100);
}

View File

@ -317,6 +317,11 @@ namespace MediaBrowser.Server.Startup.Common
/// <returns>Task.</returns>
public override async Task RunStartupTasks()
{
if (ServerConfigurationManager.Configuration.MigrationVersion < CleanDatabaseScheduledTask.MigrationVersion)
{
TaskManager.SuspendTriggers = true;
}
await base.RunStartupTasks().ConfigureAwait(false);
Logger.Info("ServerId: {0}", SystemId);

View File

@ -20,13 +20,14 @@ namespace MediaBrowser.Server.Startup.Common.Migrations
{
if (_config.Configuration.MigrationVersion < CleanDatabaseScheduledTask.MigrationVersion)
{
_taskManager.SuspendTriggers = true;
CleanDatabaseScheduledTask.EnableUnavailableMessage = true;
Task.Run(async () =>
{
await Task.Delay(1000).ConfigureAwait(false);
_taskManager.QueueScheduledTask<CleanDatabaseScheduledTask>();
_taskManager.Execute<CleanDatabaseScheduledTask>();
});
}
}