more queue fixes

This commit is contained in:
Stanley Dimant
2024-05-04 15:31:59 +02:00
parent 6ab27d9698
commit 69b5dba901

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;
@@ -169,7 +170,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)
{ {
@@ -177,13 +179,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)
{ {
@@ -191,7 +197,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;