Add rate limiting delays to prevent Spotify 429 errors

- Increase delay between playlist fetches from 1s to 3s
- Only delay between playlists, not after the last one
- Add debug logging for rate limit delays
- Spotify is very aggressive with rate limiting on their API
This commit is contained in:
2026-02-03 17:05:34 -05:00
parent 63324def62
commit fe9c1e17be

View File

@@ -297,8 +297,13 @@ public class SpotifyPlaylistFetcher : BackgroundService
_logger.LogError(ex, "Error fetching playlist '{Name}'", config.Name); _logger.LogError(ex, "Error fetching playlist '{Name}'", config.Name);
} }
// Rate limiting between playlists // Rate limiting between playlists - Spotify is VERY aggressive with rate limiting
await Task.Delay(_spotifyApiSettings.RateLimitDelayMs, cancellationToken); // Wait 3 seconds between each playlist to avoid 429 TooManyRequests errors
if (config != _spotifyImportSettings.Playlists.Last())
{
_logger.LogDebug("Waiting 3 seconds before next playlist to avoid rate limits...");
await Task.Delay(TimeSpan.FromSeconds(3), cancellationToken);
}
} }
_logger.LogInformation("=== FINISHED FETCHING SPOTIFY PLAYLISTS ==="); _logger.LogInformation("=== FINISHED FETCHING SPOTIFY PLAYLISTS ===");