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 _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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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();
|
||||||
|
@@ -36,7 +36,10 @@ 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.BlockedState(false);
|
||||||
|
if (DateTime.UtcNow > qi.NextRunTime || qi.Force == true)
|
||||||
|
{
|
||||||
qi.Execute();
|
qi.Execute();
|
||||||
if (qi.RemoveWhenStopped == true && qi.ItemState == ProcessQueue.QueueItemState.Stopped)
|
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)
|
public Task StopAsync(CancellationToken stoppingToken)
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
@@ -64,6 +64,7 @@
|
|||||||
|
|
||||||
var itemStateName;
|
var itemStateName;
|
||||||
var itemLastStart;
|
var itemLastStart;
|
||||||
|
if (result[i].IsBlocked == false) {
|
||||||
switch (result[i].itemState) {
|
switch (result[i].itemState) {
|
||||||
case 'NeverStarted':
|
case 'NeverStarted':
|
||||||
itemStateName = "Never started";
|
itemStateName = "Never started";
|
||||||
@@ -82,6 +83,10 @@
|
|||||||
itemLastStart = moment(result[i].lastRunTime).fromNow();
|
itemLastStart = moment(result[i].lastRunTime).fromNow();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
itemStateName = "Blocked";
|
||||||
|
itemLastStart = moment(result[i].lastRunTime).fromNow();
|
||||||
|
}
|
||||||
|
|
||||||
var itemInterval = result[i].interval;
|
var itemInterval = result[i].interval;
|
||||||
var nextRunTime = moment(result[i].nextRunTime).fromNow();
|
var nextRunTime = moment(result[i].nextRunTime).fromNow();
|
||||||
|
Reference in New Issue
Block a user