Add remaining seconds display during rate-limit and improve cooldown handling

This commit is contained in:
omgbeez 2026-03-07 18:04:12 -05:00 committed by Clifford Roche
parent 67afe189b5
commit 41787077db
2 changed files with 30 additions and 1 deletions

View file

@ -18,6 +18,9 @@
<strong>Debrid provider rate limit reached</strong>
<br />
Processing paused until {{ rateLimitStatus.nextDequeueTime | date: 'medium' }}
@if (rateLimitStatus.secondsRemaining > 0) {
({{ rateLimitStatus.secondsRemaining | number: '1.0-0' }} seconds remaining)
}
</div>
}
<div class="table-container">

View file

@ -13,6 +13,8 @@ namespace RdtClient.Service.Services;
public class TorrentRunner(ILogger<TorrentRunner> logger, Torrents torrents, Downloads downloads, RemoteService remoteService, IHttpClientFactory httpClientFactory, IRateLimitCoordinator coordinator)
{
private DateTimeOffset? _lastNextAllowedAt;
public static readonly ConcurrentDictionary<Guid, DownloadClient> ActiveDownloadClients = new();
public static readonly ConcurrentDictionary<Guid, UnpackClient> ActiveUnpackClients = new();
@ -113,6 +115,26 @@ public class TorrentRunner(ILogger<TorrentRunner> 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<TorrentRunner> 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
});
}