Usenet streaming with a WebDAV server and a SABnzbd-compatible API
C#
Awaken the queue immediately when a new nzb is added.
nzbdav-devd49718810eca
diff --git a/backend/Api/SabControllers/AddFile/AddFileController.cs b/backend/Api/SabControllers/AddFile/AddFileController.csindex 2c44478a..a028eb06 100644--- a/backend/Api/SabControllers/AddFile/AddFileController.cs+++ b/backend/Api/SabControllers/AddFile/AddFileController.cs@@ -53,6 +53,9 @@ public class AddFileController(var message = GetQueueResponse.QueueSlot.FromQueueItem(queueItem).ToJson();_ = websocketManager.SendMessage(WebsocketTopic.QueueItemAdded, message);+ // awaken the queue if it is sleeping+ queueManager.AwakenQueue();+// return responsereturn new AddFileResponse(){diff --git a/backend/Queue/QueueManager.cs b/backend/Queue/QueueManager.csindex 5c20fd33..5dea78dd 100644--- a/backend/Queue/QueueManager.cs+++ b/backend/Queue/QueueManager.cs@@ -20,6 +20,9 @@ public class QueueManager : IDisposableprivate readonly WebsocketManager _websocketManager;private readonly HealthCheckService _healthCheckService;+ private CancellationTokenSource _sleepingQueueToken = new();+ private readonly object _sleepingQueueLock = new();+public QueueManager(UsenetStreamingClient usenetClient,ConfigManager configManager,@@ -41,6 +44,14 @@ public class QueueManager : IDisposablereturn (_inProgressQueueItem?.QueueItem, _inProgressQueueItem?.ProgressPercentage);}+ public void AwakenQueue()+ {+ lock (_sleepingQueueLock)+ {+ _sleepingQueueToken.Cancel();+ }+ }+public async Task RemoveQueueItemsAsync(List<Guid> queueItemIds,@@ -75,9 +86,21 @@ public class QueueManager : IDisposablevar topItem = await LockAsync(() => dbClient.GetTopQueueItem(ct)).ConfigureAwait(false);if (topItem.queueItem is null || topItem.queueNzbContents is null){- // if we're done with the queue, wait- // five seconds before checking again.- await Task.Delay(TimeSpan.FromSeconds(5), ct).ConfigureAwait(false);+ try+ {+ // if we're done with the queue, wait a minute before checking again.+ // or wait until awoken by cancellation of _sleepingQueueToken+ await Task.Delay(TimeSpan.FromMinutes(1), _sleepingQueueToken.Token).ConfigureAwait(false);+ }+ catch when (_sleepingQueueToken.IsCancellationRequested)+ {+ lock (_sleepingQueueLock)+ {+ _sleepingQueueToken.Dispose();+ _sleepingQueueToken = new CancellationTokenSource();+ }+ }+continue;}@@ -112,7 +135,7 @@ public class QueueManager : IDisposable{var progressHook = new Progress<int>();var task = new QueueItemProcessor(- queueItem, queueNzbContents, dbClient, _usenetClient,+ queueItem, queueNzbContents, dbClient, _usenetClient,_configManager, _websocketManager, _healthCheckService,progressHook, cts.Token).ProcessAsync();