Skip to content

Commit

Permalink
Catch individual message send errors separately
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Apr 10, 2021
1 parent db49264 commit b3e76c3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions rss/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,20 @@ async def poll_feeds(self) -> None:
except Exception:
self.log.exception("Fatal error while polling feeds")

def _send(self, feed: Feed, entry: Entry, sub: Subscription) -> Awaitable[EventID]:
return self.client.send_markdown(sub.room_id, sub.notification_template.safe_substitute({
async def _send(self, feed: Feed, entry: Entry, sub: Subscription) -> EventID:
message = sub.notification_template.safe_substitute({
"feed_url": feed.url,
"feed_title": feed.title,
"feed_subtitle": feed.subtitle,
"feed_link": feed.link,
**entry._asdict(),
}), msgtype=MessageType.NOTICE if sub.send_notice else MessageType.TEXT, allow_html=True)
})
msgtype = MessageType.NOTICE if sub.send_notice else MessageType.TEXT
try:
return await self.client.send_markdown(sub.room_id, message, msgtype=msgtype,
allow_html=True)
except Exception as e:
self.log.warning(f"Failed to send {entry.id} of {feed.id} to {sub.room_id}: {e}")

async def _broadcast(self, feed: Feed, entry: Entry, subscriptions: List[Subscription]) -> None:
spam_sleep = self.config["spam_sleep"]
Expand Down

0 comments on commit b3e76c3

Please sign in to comment.