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;
|
_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 QueueItemType _ItemType = QueueItemType.NotConfigured;
|
||||||
private QueueItemState _ItemState = QueueItemState.NeverStarted;
|
private QueueItemState _ItemState = QueueItemState.NeverStarted;
|
||||||
private DateTime _LastRunTime = DateTime.UtcNow;
|
private DateTime _LastRunTime = DateTime.UtcNow;
|
||||||
@@ -25,6 +34,7 @@ namespace gaseous_server
|
|||||||
private string _LastResult = "";
|
private string _LastResult = "";
|
||||||
private string? _LastError = null;
|
private string? _LastError = null;
|
||||||
private bool _ForceExecute = false;
|
private bool _ForceExecute = false;
|
||||||
|
private List<QueueItemType> _Blocks = new List<QueueItemType>();
|
||||||
|
|
||||||
public QueueItemType ItemType => _ItemType;
|
public QueueItemType ItemType => _ItemType;
|
||||||
public QueueItemState ItemState => _ItemState;
|
public QueueItemState ItemState => _ItemState;
|
||||||
@@ -40,6 +50,7 @@ namespace gaseous_server
|
|||||||
public string LastResult => _LastResult;
|
public string LastResult => _LastResult;
|
||||||
public string? LastError => _LastError;
|
public string? LastError => _LastError;
|
||||||
public bool Force => _ForceExecute;
|
public bool Force => _ForceExecute;
|
||||||
|
public List<QueueItemType> Blocks => _Blocks;
|
||||||
|
|
||||||
public void Execute()
|
public void Execute()
|
||||||
{
|
{
|
||||||
|
@@ -65,8 +65,8 @@ var app = builder.Build();
|
|||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
//if (app.Environment.IsDevelopment())
|
//if (app.Environment.IsDevelopment())
|
||||||
//{
|
//{
|
||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI();
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//app.UseHttpsRedirection();
|
//app.UseHttpsRedirection();
|
||||||
@@ -92,10 +92,29 @@ gaseous_server.Classes.Metadata.Platforms.GetPlatform(0);
|
|||||||
|
|
||||||
// add background tasks
|
// add background tasks
|
||||||
ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(ProcessQueue.QueueItemType.SignatureIngestor, 60));
|
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.MetadataRefresh, 360));
|
||||||
ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(ProcessQueue.QueueItemType.OrganiseLibrary, 2040));
|
ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(
|
||||||
ProcessQueue.QueueItems.Add(new ProcessQueue.QueueItem(ProcessQueue.QueueItemType.LibraryScan, 30));
|
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
|
// start the app
|
||||||
app.Run();
|
app.Run();
|
||||||
|
@@ -34,7 +34,7 @@ namespace gaseous_server
|
|||||||
// "Timed Hosted Service is working. Count: {Count}", count);
|
// "Timed Hosted Service is working. Count: {Count}", count);
|
||||||
|
|
||||||
foreach (ProcessQueue.QueueItem qi in ProcessQueue.QueueItems) {
|
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();
|
qi.Execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,6 +54,26 @@ namespace gaseous_server
|
|||||||
{
|
{
|
||||||
_timer?.Dispose();
|
_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