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
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ require (
gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v2 v2.3.0
maunium.net/go/mautrix v0.7.0
maunium.net/go/mautrix v0.9.2
)
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 httpErr, ok := err.(mautrix.HTTPError); ok && httpErr.IsStatus(429) {
return err
} else {
logger.WithError(err).WithField("room_id", roomID).Error("Failed to send to room")
}
}
}
return nil
Expand Down