Skip to content

Commit

Permalink
Fix handling errors in feed parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Aug 3, 2020
1 parent ad39e34 commit 2079504
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion rss/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async def _poll_once(self) -> None:
subs = self.db.get_feeds()
if not subs:
return
for res in asyncio.as_completed([self.parse_feed(feed=feed) for feed in subs]):
for res in asyncio.as_completed([self.try_parse_feed(feed=feed) for feed in subs]):
feed, entries = await res
if not entries:
continue
Expand All @@ -135,6 +135,13 @@ async def _poll_feeds(self) -> None:
self.log.exception("Error while polling feeds")
await asyncio.sleep(self.config["update_interval"] * 60, loop=self.loop)

async def try_parse_feed(self, feed: Optional[Feed] = None) -> Tuple[Feed, Iterable[Entry]]:
try:
return await self.parse_feed(feed=feed)
except Exception:
self.log.exception(f"Failed to parse feed {feed.id} / {feed.url}")
return feed, []

async def parse_feed(self, *, feed: Optional[Feed] = None, url: Optional[str] = None
) -> Tuple[Feed, Iterable[Entry]]:
if feed is None:
Expand Down

0 comments on commit 2079504

Please sign in to comment.