more queue fixes

This commit is contained in:
Stanley Dimant
2024-05-04 15:31:59 +02:00
committed by Loporrit
parent a116545c9e
commit aa78432db3

View File

@@ -2,6 +2,7 @@
using MareSynchronosShared.Services; using MareSynchronosShared.Services;
using MareSynchronosStaticFilesServer.Utils; using MareSynchronosStaticFilesServer.Utils;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Linq;
using System.Timers; using System.Timers;
namespace MareSynchronosStaticFilesServer.Services; namespace MareSynchronosStaticFilesServer.Services;
@@ -156,7 +157,8 @@ public class RequestQueueService : IHostedService
while (true) while (true)
{ {
if (_priorityQueue.TryDequeue(out var prioRequest)) if (!_priorityQueue.All(u => _cachedFileProvider.AnyFilesDownloading(u.FileIds))
&& _priorityQueue.TryDequeue(out var prioRequest))
{ {
if (prioRequest.IsCancelled) if (prioRequest.IsCancelled)
{ {
@@ -164,13 +166,17 @@ public class RequestQueueService : IHostedService
} }
if (_cachedFileProvider.AnyFilesDownloading(prioRequest.FileIds)) if (_cachedFileProvider.AnyFilesDownloading(prioRequest.FileIds))
{
_priorityQueue.Enqueue(prioRequest); _priorityQueue.Enqueue(prioRequest);
continue;
}
DequeueIntoSlot(prioRequest, i); DequeueIntoSlot(prioRequest, i);
break; break;
} }
if (_queue.TryDequeue(out var request)) if (!_queue.All(u => _cachedFileProvider.AnyFilesDownloading(u.FileIds))
&& _queue.TryDequeue(out var request))
{ {
if (request.IsCancelled) if (request.IsCancelled)
{ {
@@ -178,7 +184,10 @@ public class RequestQueueService : IHostedService
} }
if (_cachedFileProvider.AnyFilesDownloading(request.FileIds)) if (_cachedFileProvider.AnyFilesDownloading(request.FileIds))
{
_queue.Enqueue(request); _queue.Enqueue(request);
continue;
}
DequeueIntoSlot(request, i); DequeueIntoSlot(request, i);
break; break;