Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Respect rate limits by not continuing to send if 429 received. #346

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions services/rssbot/rssbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ func (s *Service) OnPoll(cli types.MatrixClient) time.Time {
"feed_url": u,
log.ErrorKey: err,
"item": item,
}).Error("Failed to send item to room")
}).Error("Failed to send item to room due to 429; aborting further sends")
// no point continuing if we errored due to a 429 - we'll just hit the rate limit
// again and again
break
}
}
}
Expand Down Expand Up @@ -415,7 +418,11 @@ func (s *Service) sendToRooms(cli types.MatrixClient, feedURL string, feed *gofe
logger.Info("Sending new feed item")
for _, roomID := range s.Feeds[feedURL].Rooms {
if _, err := cli.SendMessageEvent(roomID, mevt.EventMessage, itemToHTML(feed, item)); err != nil {
logger.WithError(err).WithField("room_id", roomID).Error("Failed to send to room")
if err.Code == 429 {
michaelkaye marked this conversation as resolved.
Show resolved Hide resolved
return err
} else {
logger.WithError(err).WithField("room_id", roomID).Error("Failed to send to room")
}
}
}
return nil
Expand Down