From c61e9e94e1d42249996c64b234cb31e005bc15ca Mon Sep 17 00:00:00 2001 From: iPromKnight Date: Sun, 3 Mar 2024 19:22:10 +0000 Subject: [PATCH] Rethrow so polly captures failures on requests. --- .../Crawlers/Torrentio/TorrentioCrawler.cs | 15 ++++----------- .../Torrentio/TorrentioInstanceExtensions.cs | 13 ------------- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/src/producer/Features/Crawlers/Torrentio/TorrentioCrawler.cs b/src/producer/Features/Crawlers/Torrentio/TorrentioCrawler.cs index b74de23..2e77a38 100644 --- a/src/producer/Features/Crawlers/Torrentio/TorrentioCrawler.cs +++ b/src/producer/Features/Crawlers/Torrentio/TorrentioCrawler.cs @@ -144,10 +144,8 @@ public partial class TorrentioCrawler( catch (Exception error) { logger.LogError(error, "page processing error {TorrentioInstance}: {ImdbId}", instance.Name, imdbId); - logger.LogWarning("Setting {TorrentioInstance} to possibly rate limited for Five minutes", instance.Name); - instance.SetPossiblyRateLimited(_instanceStates); + throw; } - return null; } private async Task?> RunRequest(TorrentioInstance instance, string urlSlug, string imdbId, HttpClient client) @@ -178,15 +176,10 @@ public partial class TorrentioCrawler( var torrent = ParseTorrentDetails(title, instance, infoHash, imdId); - if (torrent is null || string.IsNullOrEmpty(torrent.Name)) - { - return null; - } - - return torrent; + return string.IsNullOrEmpty(torrent.Name) ? null : torrent; } - private Torrent? ParseTorrentDetails(string title, TorrentioInstance instance, string infoHash, string imdbId) + private Torrent ParseTorrentDetails(string title, TorrentioInstance instance, string infoHash, string imdbId) { try { @@ -226,7 +219,7 @@ public partial class TorrentioCrawler( catch (Exception e) { logger.LogError(e, "Error parsing torrent details"); - return null; + throw; } } } \ No newline at end of file diff --git a/src/producer/Features/Crawlers/Torrentio/TorrentioInstanceExtensions.cs b/src/producer/Features/Crawlers/Torrentio/TorrentioInstanceExtensions.cs index 114d698..e7a4f95 100644 --- a/src/producer/Features/Crawlers/Torrentio/TorrentioInstanceExtensions.cs +++ b/src/producer/Features/Crawlers/Torrentio/TorrentioInstanceExtensions.cs @@ -21,20 +21,7 @@ public static class TorrentioInstancesExtensions return remaining > TimeSpan.Zero ? remaining : TimeSpan.Zero; } - - public static void SetPossiblyRateLimited(this TorrentioInstance instance, Dictionary scraperState, int minutesToWait = 5) - { - var state = instance.EnsureStateExists(scraperState); - // Set the start time to 15 minutes in the past so that the next check will result in a rate limit period of 15 minutes - var startedAt = DateTime.UtcNow.AddMinutes(-minutesToWait); - var requestCount = instance.RateLimit.RequestLimit; - - // Update the scraper state for the instance - state.StartedAt = startedAt; - state.RequestCount = requestCount; - } - public static long TotalProcessedRequests(this TorrentioInstance instance, Dictionary scraperState) => !scraperState.TryGetValue(instance.Name, out var state) ? 0 : state.TotalProcessed;