Other processes should now be blocked during database upgrade processes (#128)

This commit is contained in:
Michael Green
2023-09-22 06:42:24 -07:00
committed by GitHub
parent 9b930b2a51
commit fff22ea8d9
4 changed files with 101 additions and 30 deletions

View File

@@ -54,6 +54,7 @@ namespace gaseous_server
private bool _ForceExecute = false; private bool _ForceExecute = false;
private bool _AllowManualStart = true; private bool _AllowManualStart = true;
private bool _RemoveWhenStopped = false; private bool _RemoveWhenStopped = false;
private bool _IsBlocked = false;
private List<QueueItemType> _Blocks = new List<QueueItemType>(); private List<QueueItemType> _Blocks = new List<QueueItemType>();
public QueueItemType ItemType => _ItemType; public QueueItemType ItemType => _ItemType;
@@ -72,6 +73,7 @@ namespace gaseous_server
public bool Force => _ForceExecute; public bool Force => _ForceExecute;
public bool AllowManualStart => _AllowManualStart; public bool AllowManualStart => _AllowManualStart;
public bool RemoveWhenStopped => _RemoveWhenStopped; public bool RemoveWhenStopped => _RemoveWhenStopped;
public bool IsBlocked => _IsBlocked;
public object? Options { get; set; } = null; public object? Options { get; set; } = null;
public List<QueueItemType> Blocks => _Blocks; public List<QueueItemType> Blocks => _Blocks;
@@ -172,17 +174,58 @@ namespace gaseous_server
{ {
_ForceExecute = true; _ForceExecute = true;
} }
public void BlockedState(bool BlockState)
{
_IsBlocked = BlockState;
}
} }
public enum QueueItemType 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, NotConfigured,
/// <summary>
/// Ingests signature DAT files into the database
/// </summary>
SignatureIngestor, SignatureIngestor,
/// <summary>
/// Imports game files into the database and moves them to the required location on disk
/// </summary>
TitleIngestor, TitleIngestor,
/// <summary>
/// Forces stored metadata to be refreshed
/// </summary>
MetadataRefresh, MetadataRefresh,
/// <summary>
/// Ensures all managed files are where they are supposed to be
/// </summary>
OrganiseLibrary, OrganiseLibrary,
/// <summary>
/// Looks for orphaned files in the library and re-adds them to the database
/// </summary>
LibraryScan, LibraryScan,
/// <summary>
/// Builds collections - set the options attribute to the id of the collection to build
/// </summary>
CollectionCompiler, CollectionCompiler,
/// <summary>
/// Performs and post database upgrade scripts that can be processed as a background task
/// </summary>
BackgroundDatabaseUpgrade BackgroundDatabaseUpgrade
} }

View File

@@ -29,6 +29,23 @@ if (Config.ReadSetting("API Key", "Test API Key") == "Test API Key")
Config.SetSetting("API Key", APIKey.ToString()); 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 // set up server
var builder = WebApplication.CreateBuilder(args); 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 // start the app
app.Run(); app.Run();

View File

@@ -36,13 +36,21 @@ namespace gaseous_server
List<ProcessQueue.QueueItem> ActiveList = new List<ProcessQueue.QueueItem>(); List<ProcessQueue.QueueItem> ActiveList = new List<ProcessQueue.QueueItem>();
ActiveList.AddRange(ProcessQueue.QueueItems); ActiveList.AddRange(ProcessQueue.QueueItems);
foreach (ProcessQueue.QueueItem qi in ActiveList) { foreach (ProcessQueue.QueueItem qi in ActiveList) {
if ((DateTime.UtcNow > qi.NextRunTime || qi.Force == true) && CheckProcessBlockList(qi) == true) { if (CheckProcessBlockList(qi) == true) {
qi.Execute(); qi.BlockedState(false);
if (qi.RemoveWhenStopped == true && qi.ItemState == ProcessQueue.QueueItemState.Stopped) if (DateTime.UtcNow > qi.NextRunTime || qi.Force == true)
{ {
ProcessQueue.QueueItems.Remove(qi); qi.Execute();
if (qi.RemoveWhenStopped == true && qi.ItemState == ProcessQueue.QueueItemState.Stopped)
{
ProcessQueue.QueueItems.Remove(qi);
}
} }
} }
else
{
qi.BlockedState(true);
}
} }
} }
@@ -67,7 +75,13 @@ namespace gaseous_server
{ {
foreach (ProcessQueue.QueueItem qi in ProcessQueue.QueueItems) 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; return false;
} }

View File

@@ -64,23 +64,28 @@
var itemStateName; var itemStateName;
var itemLastStart; var itemLastStart;
switch (result[i].itemState) { if (result[i].IsBlocked == false) {
case 'NeverStarted': switch (result[i].itemState) {
itemStateName = "Never started"; case 'NeverStarted':
itemLastStart = '-'; itemStateName = "Never started";
break; itemLastStart = '-';
case 'Stopped': break;
itemStateName = "Stopped"; case 'Stopped':
itemLastStart = moment(result[i].lastRunTime).fromNow(); itemStateName = "Stopped";
break; itemLastStart = moment(result[i].lastRunTime).fromNow();
case 'Running': break;
itemStateName = "Running"; case 'Running':
itemLastStart = moment(result[i].lastRunTime).fromNow(); itemStateName = "Running";
break; itemLastStart = moment(result[i].lastRunTime).fromNow();
default: break;
itemStateName = "Unknown status"; default:
itemLastStart = moment(result[i].lastRunTime).fromNow(); itemStateName = "Unknown status";
break; itemLastStart = moment(result[i].lastRunTime).fromNow();
break;
}
} else {
itemStateName = "Blocked";
itemLastStart = moment(result[i].lastRunTime).fromNow();
} }
var itemInterval = result[i].interval; var itemInterval = result[i].interval;