diff --git a/gaseous-server/ProcessQueue.cs b/gaseous-server/ProcessQueue.cs index 19d4b0e..98f8fc8 100644 --- a/gaseous-server/ProcessQueue.cs +++ b/gaseous-server/ProcessQueue.cs @@ -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 _Blocks = new List(); 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 Blocks => _Blocks; @@ -172,17 +174,58 @@ namespace gaseous_server { _ForceExecute = true; } + + public void BlockedState(bool BlockState) + { + _IsBlocked = BlockState; + } } public enum QueueItemType { + /// + /// Reserved for blocking all services - no actual background service is tied to this type + /// + All, + + /// + /// Default type - no background service is tied to this type + /// NotConfigured, + + /// + /// Ingests signature DAT files into the database + /// SignatureIngestor, + + /// + /// Imports game files into the database and moves them to the required location on disk + /// TitleIngestor, + + /// + /// Forces stored metadata to be refreshed + /// MetadataRefresh, + + /// + /// Ensures all managed files are where they are supposed to be + /// OrganiseLibrary, + + /// + /// Looks for orphaned files in the library and re-adds them to the database + /// LibraryScan, + + /// + /// Builds collections - set the options attribute to the id of the collection to build + /// CollectionCompiler, + + /// + /// Performs and post database upgrade scripts that can be processed as a background task + /// BackgroundDatabaseUpgrade } diff --git a/gaseous-server/Program.cs b/gaseous-server/Program.cs index 3027a9c..5e817a1 100644 --- a/gaseous-server/Program.cs +++ b/gaseous-server/Program.cs @@ -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.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(); diff --git a/gaseous-server/Timer.cs b/gaseous-server/Timer.cs index 2ca1573..d6653ad 100644 --- a/gaseous-server/Timer.cs +++ b/gaseous-server/Timer.cs @@ -36,13 +36,21 @@ namespace gaseous_server List ActiveList = new List(); ActiveList.AddRange(ProcessQueue.QueueItems); foreach (ProcessQueue.QueueItem qi in ActiveList) { - if ((DateTime.UtcNow > qi.NextRunTime || qi.Force == true) && CheckProcessBlockList(qi) == true) { - qi.Execute(); - if (qi.RemoveWhenStopped == true && qi.ItemState == ProcessQueue.QueueItemState.Stopped) + if (CheckProcessBlockList(qi) == true) { + qi.BlockedState(false); + 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) { - 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; } diff --git a/gaseous-server/wwwroot/pages/settings/system.html b/gaseous-server/wwwroot/pages/settings/system.html index d546694..772edaf 100644 --- a/gaseous-server/wwwroot/pages/settings/system.html +++ b/gaseous-server/wwwroot/pages/settings/system.html @@ -64,23 +64,28 @@ var itemStateName; var itemLastStart; - switch (result[i].itemState) { - case 'NeverStarted': - itemStateName = "Never started"; - itemLastStart = '-'; - break; - case 'Stopped': - itemStateName = "Stopped"; - itemLastStart = moment(result[i].lastRunTime).fromNow(); - break; - case 'Running': - itemStateName = "Running"; - itemLastStart = moment(result[i].lastRunTime).fromNow(); - break; - default: - itemStateName = "Unknown status"; - itemLastStart = moment(result[i].lastRunTime).fromNow(); - break; + if (result[i].IsBlocked == false) { + switch (result[i].itemState) { + case 'NeverStarted': + itemStateName = "Never started"; + itemLastStart = '-'; + break; + case 'Stopped': + itemStateName = "Stopped"; + itemLastStart = moment(result[i].lastRunTime).fromNow(); + break; + case 'Running': + itemStateName = "Running"; + itemLastStart = moment(result[i].lastRunTime).fromNow(); + break; + default: + itemStateName = "Unknown status"; + itemLastStart = moment(result[i].lastRunTime).fromNow(); + break; + } + } else { + itemStateName = "Blocked"; + itemLastStart = moment(result[i].lastRunTime).fromNow(); } var itemInterval = result[i].interval;