sanitize queue processing
This commit is contained in:
@@ -35,6 +35,8 @@ public class RequestQueueService : IHostedService
|
||||
return QueueStatus.Waiting;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await _queueSemaphore.WaitAsync().ConfigureAwait(false);
|
||||
QueueStatus status = QueueStatus.Waiting;
|
||||
var idx = Array.FindIndex(_userQueueRequests, r => r == null);
|
||||
@@ -48,10 +50,20 @@ public class RequestQueueService : IHostedService
|
||||
DequeueIntoSlot(request, idx);
|
||||
status = QueueStatus.Ready;
|
||||
}
|
||||
_queueSemaphore.Release();
|
||||
|
||||
return status;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during EnqueueUser");
|
||||
}
|
||||
finally
|
||||
{
|
||||
_queueSemaphore.Release();
|
||||
}
|
||||
|
||||
throw new Exception("Error during EnqueueUser");
|
||||
}
|
||||
|
||||
public bool StillEnqueued(Guid request, string user, out int queuePosition)
|
||||
{
|
||||
@@ -91,6 +103,8 @@ public class RequestQueueService : IHostedService
|
||||
private async Task ProcessRequestQueue(CancellationToken ct)
|
||||
{
|
||||
while (!ct.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _queueProcessingSemaphore.WaitAsync(ct).ConfigureAwait(false);
|
||||
await _queueSemaphore.WaitAsync(ct).ConfigureAwait(false);
|
||||
@@ -108,8 +122,17 @@ public class RequestQueueService : IHostedService
|
||||
|
||||
if (!_queue.Any()) break;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during Queue processing");
|
||||
}
|
||||
finally
|
||||
{
|
||||
_queueProcessingSemaphore.Release();
|
||||
_queueSemaphore.Release();
|
||||
}
|
||||
|
||||
_metrics.SetGaugeTo(MetricsAPI.GaugeDownloadQueue, _queue.Count);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user