From 25ddd50de79c62c0a632bb09547f853d8881b9ac Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Mon, 1 Mar 2021 16:22:34 +0000 Subject: [PATCH 1/5] Respect rate limits by not continuing to send if 429 received. --- services/rssbot/rssbot.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/services/rssbot/rssbot.go b/services/rssbot/rssbot.go index c339975..c1e1ae8 100644 --- a/services/rssbot/rssbot.go +++ b/services/rssbot/rssbot.go @@ -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 } } } @@ -415,7 +418,12 @@ 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 { + return err + } + else { + logger.WithError(err).WithField("room_id", roomID).Error("Failed to send to room") + } } } return nil From 37d6cffab14f31a8b6feffd7d798a3eea5ac2ec1 Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Thu, 4 Mar 2021 17:22:16 +0000 Subject: [PATCH 2/5] Typo in a test --- services/rssbot/rssbot.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/services/rssbot/rssbot.go b/services/rssbot/rssbot.go index c1e1ae8..a031ab4 100644 --- a/services/rssbot/rssbot.go +++ b/services/rssbot/rssbot.go @@ -418,10 +418,9 @@ 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 { - if err.code = 429 { + if err.code == 429 { return err - } - else { + } else { logger.WithError(err).WithField("room_id", roomID).Error("Failed to send to room") } } From 93538495757c9f4db76d2c2b84f2c385139a783b Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Thu, 4 Mar 2021 18:08:46 +0000 Subject: [PATCH 3/5] s/code/Code/ after reading the gomatrix lib --- services/rssbot/rssbot.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/rssbot/rssbot.go b/services/rssbot/rssbot.go index a031ab4..35235cb 100644 --- a/services/rssbot/rssbot.go +++ b/services/rssbot/rssbot.go @@ -418,7 +418,7 @@ 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 { - if err.code == 429 { + if err.Code == 429 { return err } else { logger.WithError(err).WithField("room_id", roomID).Error("Failed to send to room") From 0d8182086321f6f57ff5cf81e722a7c343476118 Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Wed, 24 Mar 2021 07:56:26 +0000 Subject: [PATCH 4/5] Apply suggestions from code review Co-authored-by: Tulir Asokan --- services/rssbot/rssbot.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/rssbot/rssbot.go b/services/rssbot/rssbot.go index 35235cb..1e46cce 100644 --- a/services/rssbot/rssbot.go +++ b/services/rssbot/rssbot.go @@ -418,7 +418,7 @@ 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 { - if err.Code == 429 { + 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") From e9f5ef10ec7d7f3c132928d2ec321e39e96aa7f6 Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Wed, 24 Mar 2021 08:02:02 +0000 Subject: [PATCH 5/5] Update to 0.9.2 of mautrix library --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 6e253ae..2e0d292 100644 --- a/go.mod +++ b/go.mod @@ -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 )