Other processes should now be blocked during database upgrade processes (#128)
This commit is contained in:
@@ -54,6 +54,7 @@ namespace gaseous_server
|
||||
private bool _ForceExecute = false;
|
||||
private bool _AllowManualStart = true;
|
||||
private bool _RemoveWhenStopped = false;
|
||||
private bool _IsBlocked = false;
|
||||
private List<QueueItemType> _Blocks = new List<QueueItemType>();
|
||||
|
||||
public QueueItemType ItemType => _ItemType;
|
||||
@@ -72,6 +73,7 @@ namespace gaseous_server
|
||||
public bool Force => _ForceExecute;
|
||||
public bool AllowManualStart => _AllowManualStart;
|
||||
public bool RemoveWhenStopped => _RemoveWhenStopped;
|
||||
public bool IsBlocked => _IsBlocked;
|
||||
public object? Options { get; set; } = null;
|
||||
public List<QueueItemType> Blocks => _Blocks;
|
||||
|
||||
@@ -172,17 +174,58 @@ namespace gaseous_server
|
||||
{
|
||||
_ForceExecute = true;
|
||||
}
|
||||
|
||||
public void BlockedState(bool BlockState)
|
||||
{
|
||||
_IsBlocked = BlockState;
|
||||
}
|
||||
}
|
||||
|
||||
public enum QueueItemType
|
||||
{
|
||||
/// <summary>
|
||||
/// Reserved for blocking all services - no actual background service is tied to this type
|
||||
/// </summary>
|
||||
All,
|
||||
|
||||
/// <summary>
|
||||
/// Default type - no background service is tied to this type
|
||||
/// </summary>
|
||||
NotConfigured,
|
||||
|
||||
/// <summary>
|
||||
/// Ingests signature DAT files into the database
|
||||
/// </summary>
|
||||
SignatureIngestor,
|
||||
|
||||
/// <summary>
|
||||
/// Imports game files into the database and moves them to the required location on disk
|
||||
/// </summary>
|
||||
TitleIngestor,
|
||||
|
||||
/// <summary>
|
||||
/// Forces stored metadata to be refreshed
|
||||
/// </summary>
|
||||
MetadataRefresh,
|
||||
|
||||
/// <summary>
|
||||
/// Ensures all managed files are where they are supposed to be
|
||||
/// </summary>
|
||||
OrganiseLibrary,
|
||||
|
||||
/// <summary>
|
||||
/// Looks for orphaned files in the library and re-adds them to the database
|
||||
/// </summary>
|
||||
LibraryScan,
|
||||
|
||||
/// <summary>
|
||||
/// Builds collections - set the options attribute to the id of the collection to build
|
||||
/// </summary>
|
||||
CollectionCompiler,
|
||||
|
||||
/// <summary>
|
||||
/// Performs and post database upgrade scripts that can be processed as a background task
|
||||
/// </summary>
|
||||
BackgroundDatabaseUpgrade
|
||||
}
|
||||
|
||||
|
@@ -29,6 +29,23 @@ if (Config.ReadSetting("API Key", "Test API Key") == "Test API Key")
|
||||
Config.SetSetting("API Key", APIKey.ToString());
|
||||
}
|
||||
|
||||
// kick off any delayed upgrade tasks
|
||||
// run 1002 background updates in the background on every start
|
||||
DatabaseMigration.BackgroundUpgradeTargetSchemaVersions.Add(1002);
|
||||
// start the task
|
||||
ProcessQueue.QueueItem queueItem = new ProcessQueue.QueueItem(
|
||||
ProcessQueue.QueueItemType.BackgroundDatabaseUpgrade,
|
||||
1,
|
||||
new List<ProcessQueue.QueueItemType>
|
||||
{
|
||||
ProcessQueue.QueueItemType.All
|
||||
},
|
||||
false,
|
||||
true
|
||||
);
|
||||
queueItem.ForceExecute();
|
||||
ProcessQueue.QueueItems.Add(queueItem);
|
||||
|
||||
// set up server
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@@ -171,13 +188,5 @@ ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(
|
||||
})
|
||||
);
|
||||
|
||||
// kick off any delayed upgrade tasks
|
||||
// run 1002 background updates in the background on every start
|
||||
DatabaseMigration.BackgroundUpgradeTargetSchemaVersions.Add(1002);
|
||||
// start the task
|
||||
ProcessQueue.QueueItem queueItem = new ProcessQueue.QueueItem(ProcessQueue.QueueItemType.BackgroundDatabaseUpgrade, 1, false, true);
|
||||
queueItem.ForceExecute();
|
||||
ProcessQueue.QueueItems.Add(queueItem);
|
||||
|
||||
// start the app
|
||||
app.Run();
|
||||
|
@@ -36,7 +36,10 @@ namespace gaseous_server
|
||||
List<ProcessQueue.QueueItem> ActiveList = new List<ProcessQueue.QueueItem>();
|
||||
ActiveList.AddRange(ProcessQueue.QueueItems);
|
||||
foreach (ProcessQueue.QueueItem qi in ActiveList) {
|
||||
if ((DateTime.UtcNow > qi.NextRunTime || qi.Force == true) && CheckProcessBlockList(qi) == true) {
|
||||
if (CheckProcessBlockList(qi) == true) {
|
||||
qi.BlockedState(false);
|
||||
if (DateTime.UtcNow > qi.NextRunTime || qi.Force == true)
|
||||
{
|
||||
qi.Execute();
|
||||
if (qi.RemoveWhenStopped == true && qi.ItemState == ProcessQueue.QueueItemState.Stopped)
|
||||
{
|
||||
@@ -44,6 +47,11 @@ namespace gaseous_server
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qi.BlockedState(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken stoppingToken)
|
||||
@@ -67,7 +75,13 @@ namespace gaseous_server
|
||||
{
|
||||
foreach (ProcessQueue.QueueItem qi in ProcessQueue.QueueItems)
|
||||
{
|
||||
if (queueItem.Blocks.Contains(qi.ItemType) && qi.ItemState == ProcessQueue.QueueItemState.Running)
|
||||
if (
|
||||
(
|
||||
queueItem.Blocks.Contains(qi.ItemType) ||
|
||||
queueItem.Blocks.Contains(ProcessQueue.QueueItemType.All)
|
||||
) &&
|
||||
qi.ItemState == ProcessQueue.QueueItemState.Running
|
||||
)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@@ -64,6 +64,7 @@
|
||||
|
||||
var itemStateName;
|
||||
var itemLastStart;
|
||||
if (result[i].IsBlocked == false) {
|
||||
switch (result[i].itemState) {
|
||||
case 'NeverStarted':
|
||||
itemStateName = "Never started";
|
||||
@@ -82,6 +83,10 @@
|
||||
itemLastStart = moment(result[i].lastRunTime).fromNow();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
itemStateName = "Blocked";
|
||||
itemLastStart = moment(result[i].lastRunTime).fromNow();
|
||||
}
|
||||
|
||||
var itemInterval = result[i].interval;
|
||||
var nextRunTime = moment(result[i].nextRunTime).fromNow();
|
||||
|
Reference in New Issue
Block a user