fix: added process blocking to prevent competing processes from running at the same time
This commit is contained in:
@@ -17,6 +17,15 @@ namespace gaseous_server
|
||||
_Interval = ExecutionInterval;
|
||||
}
|
||||
|
||||
public QueueItem(QueueItemType ItemType, int ExecutionInterval, List<QueueItemType> Blocks)
|
||||
{
|
||||
_ItemType = ItemType;
|
||||
_ItemState = QueueItemState.NeverStarted;
|
||||
_LastRunTime = DateTime.UtcNow.AddMinutes(ExecutionInterval);
|
||||
_Interval = ExecutionInterval;
|
||||
_Blocks = Blocks;
|
||||
}
|
||||
|
||||
private QueueItemType _ItemType = QueueItemType.NotConfigured;
|
||||
private QueueItemState _ItemState = QueueItemState.NeverStarted;
|
||||
private DateTime _LastRunTime = DateTime.UtcNow;
|
||||
@@ -25,6 +34,7 @@ namespace gaseous_server
|
||||
private string _LastResult = "";
|
||||
private string? _LastError = null;
|
||||
private bool _ForceExecute = false;
|
||||
private List<QueueItemType> _Blocks = new List<QueueItemType>();
|
||||
|
||||
public QueueItemType ItemType => _ItemType;
|
||||
public QueueItemState ItemState => _ItemState;
|
||||
@@ -40,6 +50,7 @@ namespace gaseous_server
|
||||
public string LastResult => _LastResult;
|
||||
public string? LastError => _LastError;
|
||||
public bool Force => _ForceExecute;
|
||||
public List<QueueItemType> Blocks => _Blocks;
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
|
@@ -65,8 +65,8 @@ var app = builder.Build();
|
||||
// Configure the HTTP request pipeline.
|
||||
//if (app.Environment.IsDevelopment())
|
||||
//{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
//}
|
||||
|
||||
//app.UseHttpsRedirection();
|
||||
@@ -92,10 +92,29 @@ gaseous_server.Classes.Metadata.Platforms.GetPlatform(0);
|
||||
|
||||
// add background tasks
|
||||
ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(ProcessQueue.QueueItemType.SignatureIngestor, 60));
|
||||
ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(ProcessQueue.QueueItemType.TitleIngestor, 1));
|
||||
ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(
|
||||
ProcessQueue.QueueItemType.TitleIngestor, 1,
|
||||
new List<ProcessQueue.QueueItemType>
|
||||
{
|
||||
ProcessQueue.QueueItemType.OrganiseLibrary,
|
||||
ProcessQueue.QueueItemType.LibraryScan
|
||||
})
|
||||
);
|
||||
ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(ProcessQueue.QueueItemType.MetadataRefresh, 360));
|
||||
ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(ProcessQueue.QueueItemType.OrganiseLibrary, 2040));
|
||||
ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(ProcessQueue.QueueItemType.LibraryScan, 30));
|
||||
ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(
|
||||
ProcessQueue.QueueItemType.OrganiseLibrary, 2040, new List<ProcessQueue.QueueItemType>
|
||||
{
|
||||
ProcessQueue.QueueItemType.LibraryScan,
|
||||
ProcessQueue.QueueItemType.TitleIngestor
|
||||
})
|
||||
);
|
||||
ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(
|
||||
ProcessQueue.QueueItemType.LibraryScan, 30, new List<ProcessQueue.QueueItemType>
|
||||
{
|
||||
ProcessQueue.QueueItemType.TitleIngestor,
|
||||
ProcessQueue.QueueItemType.OrganiseLibrary
|
||||
})
|
||||
);
|
||||
|
||||
// start the app
|
||||
app.Run();
|
||||
|
@@ -34,7 +34,7 @@ namespace gaseous_server
|
||||
// "Timed Hosted Service is working. Count: {Count}", count);
|
||||
|
||||
foreach (ProcessQueue.QueueItem qi in ProcessQueue.QueueItems) {
|
||||
if (DateTime.UtcNow > qi.NextRunTime || qi.Force == true) {
|
||||
if ((DateTime.UtcNow > qi.NextRunTime || qi.Force == true) && CheckProcessBlockList(qi) == true) {
|
||||
qi.Execute();
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,26 @@ namespace gaseous_server
|
||||
{
|
||||
_timer?.Dispose();
|
||||
}
|
||||
|
||||
private bool CheckProcessBlockList(ProcessQueue.QueueItem queueItem)
|
||||
{
|
||||
if (queueItem.Blocks.Count > 0)
|
||||
{
|
||||
foreach (ProcessQueue.QueueItem qi in ProcessQueue.QueueItems)
|
||||
{
|
||||
if (queueItem.Blocks.Contains(qi.ItemType) && qi.ItemState == ProcessQueue.QueueItemState.Running)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user