Add remaining seconds display during rate-limit and improve cooldown handling
This commit is contained in:
parent
67afe189b5
commit
41787077db
2 changed files with 30 additions and 1 deletions
|
|
@ -18,6 +18,9 @@
|
||||||
<strong>Debrid provider rate limit reached</strong>
|
<strong>Debrid provider rate limit reached</strong>
|
||||||
<br />
|
<br />
|
||||||
Processing paused until {{ rateLimitStatus.nextDequeueTime | date: 'medium' }}
|
Processing paused until {{ rateLimitStatus.nextDequeueTime | date: 'medium' }}
|
||||||
|
@if (rateLimitStatus.secondsRemaining > 0) {
|
||||||
|
({{ rateLimitStatus.secondsRemaining | number: '1.0-0' }} seconds remaining)
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
<div class="table-container">
|
<div class="table-container">
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ namespace RdtClient.Service.Services;
|
||||||
|
|
||||||
public class TorrentRunner(ILogger<TorrentRunner> logger, Torrents torrents, Downloads downloads, RemoteService remoteService, IHttpClientFactory httpClientFactory, IRateLimitCoordinator coordinator)
|
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, DownloadClient> ActiveDownloadClients = new();
|
||||||
public static readonly ConcurrentDictionary<Guid, UnpackClient> ActiveUnpackClients = 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();
|
var sw = new Stopwatch();
|
||||||
sw.Start();
|
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)
|
if (!ActiveDownloadClients.IsEmpty || !ActiveUnpackClients.IsEmpty)
|
||||||
{
|
{
|
||||||
Log($"TorrentRunner Tick Start, {ActiveDownloadClients.Count} active downloads, {ActiveUnpackClients.Count} active unpacks");
|
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);
|
coordinator.UpdateCooldown("General", retryAfter);
|
||||||
var nextDequeueTime = coordinator.GetMaxNextAllowedAt();
|
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}");
|
Log($"Rate-limit reached, pausing dequeuing for {retryAfter.TotalMinutes} minutes (until {nextDequeueTime}): {message}");
|
||||||
|
|
||||||
|
_lastNextAllowedAt = nextDequeueTime;
|
||||||
|
|
||||||
await remoteService.UpdateRateLimitStatus(new()
|
await remoteService.UpdateRateLimitStatus(new()
|
||||||
{
|
{
|
||||||
NextDequeueTime = nextDequeueTime,
|
NextDequeueTime = nextDequeueTime,
|
||||||
SecondsRemaining = retryAfter.TotalSeconds
|
SecondsRemaining = secondsRemaining
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue