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