fix: retry transient RSS fetch failures with backoff

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-03 16:39:11 +08:00
parent f6fac7b642
commit 64179820d7
3 changed files with 52 additions and 9 deletions

View File

@@ -29,6 +29,42 @@ def test_rss_user_agent_avoids_bot_blocked_feeds():
assert "daily-robots" not in RSS_USER_AGENT
def test_fetch_one_retries_transient_errors(monkeypatch):
import httpx
from daily.news.feeds import NEWS_CATEGORIES
from daily.news import fetch as news_fetch
monkeypatch.setenv("DAILY_RSS_RETRY", "2")
monkeypatch.setattr(news_fetch.time, "sleep", lambda _: None)
category = NEWS_CATEGORIES[0]
feed = category.feeds[0]
calls = {"n": 0}
class FakeResponse:
def raise_for_status(self):
return None
@property
def text(self):
return (FIXTURES / "sample-rss.xml").read_text(encoding="utf-8")
class FakeClient:
headers = {"User-Agent": "test"}
def get(self, url, headers=None):
calls["n"] += 1
if calls["n"] < 2:
raise httpx.RemoteProtocolError("Server disconnected")
return FakeResponse()
entries, ok = news_fetch._fetch_one(FakeClient(), category, feed)
assert ok is True
assert len(entries) == 1
assert calls["n"] == 2
def test_fetch_ai_news_offline(monkeypatch):
from daily.news import fetch as news_fetch