fix: skip API calls when all keys are rate-limited in -collect mode
Pre-flight check on the CollectNotes loop now sleeps until at least one key recovers instead of issuing a wasted 429-bound request per iteration. Extracts the countdown into ApiKeyPool.SleepUntilAnyAvailable (30s refresh) and reuses it in CollectLikes and GrabNotes. Co-Authored-By: Claude Opus 4.7 <[email protected]>
This commit is contained in:
@@ -1948,6 +1948,28 @@ namespace URLNotesGrabberCORE
|
||||
return all;
|
||||
}
|
||||
|
||||
public static void SleepUntilAnyAvailable(int refreshSeconds = 30)
|
||||
{
|
||||
if (refreshSeconds <= 0) refreshSeconds = 30;
|
||||
if (!IsAllRateLimited(out int minRetry) || minRetry <= 0) return;
|
||||
|
||||
DateTime retryAt = DateTime.Now.AddSeconds(minRetry);
|
||||
int remaining = minRetry;
|
||||
while (remaining > 0)
|
||||
{
|
||||
Console.WriteLine("[Pool] All API keys rate-limited. Sleeping {0}s, until {1}", remaining, retryAt.ToString("T"));
|
||||
int sleepSeconds = Math.Min(refreshSeconds, remaining);
|
||||
Thread.Sleep(sleepSeconds * 1000);
|
||||
remaining -= sleepSeconds;
|
||||
|
||||
if (remaining > 0 && IsAllRateLimited(out int refreshed) && refreshed > 0 && refreshed < remaining)
|
||||
{
|
||||
remaining = refreshed;
|
||||
retryAt = DateTime.Now.AddSeconds(remaining);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void SaveState()
|
||||
{
|
||||
using var conn = new System.Data.SQLite.SQLiteConnection("Data Source=" + _dbPath);
|
||||
|
||||
Reference in New Issue
Block a user