From 41787077dbc482b32e413e6b87c62c796f092f7a Mon Sep 17 00:00:00 2001 From: omgbeez <251408589+omgbeez@users.noreply.github.com> Date: Sat, 7 Mar 2026 18:04:12 -0500 Subject: [PATCH] Add remaining seconds display during rate-limit and improve cooldown handling --- .../torrent-table.component.html | 3 ++ .../Services/TorrentRunner.cs | 28 ++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/client/src/app/torrent-table/torrent-table.component.html b/client/src/app/torrent-table/torrent-table.component.html index c3b26ee..7c170d8 100644 --- a/client/src/app/torrent-table/torrent-table.component.html +++ b/client/src/app/torrent-table/torrent-table.component.html @@ -18,6 +18,9 @@ Debrid provider rate limit reached
Processing paused until {{ rateLimitStatus.nextDequeueTime | date: 'medium' }} + @if (rateLimitStatus.secondsRemaining > 0) { + ({{ rateLimitStatus.secondsRemaining | number: '1.0-0' }} seconds remaining) + } }
diff --git a/server/RdtClient.Service/Services/TorrentRunner.cs b/server/RdtClient.Service/Services/TorrentRunner.cs index 2256473..8be94f2 100644 --- a/server/RdtClient.Service/Services/TorrentRunner.cs +++ b/server/RdtClient.Service/Services/TorrentRunner.cs @@ -13,6 +13,8 @@ namespace RdtClient.Service.Services; public class TorrentRunner(ILogger logger, Torrents torrents, Downloads downloads, RemoteService remoteService, IHttpClientFactory httpClientFactory, IRateLimitCoordinator coordinator) { + private DateTimeOffset? _lastNextAllowedAt; + public static readonly ConcurrentDictionary ActiveDownloadClients = new(); public static readonly ConcurrentDictionary ActiveUnpackClients = new(); @@ -113,6 +115,26 @@ public class TorrentRunner(ILogger logger, Torrents torrents, Dow var sw = new Stopwatch(); sw.Start(); + var currentNextAllowedAt = coordinator.GetMaxNextAllowedAt(); + if (currentNextAllowedAt != _lastNextAllowedAt) + { + if (currentNextAllowedAt == null || currentNextAllowedAt <= DateTimeOffset.UtcNow) + { + if (_lastNextAllowedAt > DateTimeOffset.UtcNow) + { + Log("Rate-limit cooldown expired, resuming dequeuing"); + + await remoteService.UpdateRateLimitStatus(new() + { + NextDequeueTime = null, + SecondsRemaining = 0 + }); + } + } + + _lastNextAllowedAt = currentNextAllowedAt; + } + if (!ActiveDownloadClients.IsEmpty || !ActiveUnpackClients.IsEmpty) { Log($"TorrentRunner Tick Start, {ActiveDownloadClients.Count} active downloads, {ActiveUnpackClients.Count} active unpacks"); @@ -742,13 +764,17 @@ public class TorrentRunner(ILogger logger, Torrents torrents, Dow { coordinator.UpdateCooldown("General", retryAfter); var nextDequeueTime = coordinator.GetMaxNextAllowedAt(); + var now = DateTimeOffset.UtcNow; + var secondsRemaining = nextDequeueTime.HasValue ? (nextDequeueTime.Value - now).TotalSeconds : 0; Log($"Rate-limit reached, pausing dequeuing for {retryAfter.TotalMinutes} minutes (until {nextDequeueTime}): {message}"); + _lastNextAllowedAt = nextDequeueTime; + await remoteService.UpdateRateLimitStatus(new() { NextDequeueTime = nextDequeueTime, - SecondsRemaining = retryAfter.TotalSeconds + SecondsRemaining = secondsRemaining }); }