diff options
author | Alex Vandiver <github@chmrr.net> | 2021-10-23 14:46:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-23 23:46:27 +0200 |
commit | e3ffbcadd82d71e87e7f5841f9a037f9358a010b (patch) | |
tree | 82b5e6588254d587e07ff23541090f46527cc8f5 /bridge/zulip/zulip.go | |
parent | b7d73077e5944056c1078ed22a3211e6a11ffad4 (diff) | |
download | matterbridge-msglm-e3ffbcadd82d71e87e7f5841f9a037f9358a010b.tar.gz matterbridge-msglm-e3ffbcadd82d71e87e7f5841f9a037f9358a010b.tar.bz2 matterbridge-msglm-e3ffbcadd82d71e87e7f5841f9a037f9358a010b.zip |
Add better error handling on Zulip (#1589)
* zulip: Treat unknown errors with a 10-second backoff.
An unknown error (including an unauthorized error) would fall through
with no calls to time.Sleep, resulting in hammering the server as
quickly as possible.
Add a 10-second sleep in the default error case. The heartbeat is
left with no explicit sleep, but all other codepaths now contain one.
* version: Move version information into a separate package.
This will allow it to be accessed by other sections of the code.
* zulip: Use the matterbridge version in the user-agent.
Co-authored-by: Wim <wim@42.be>
Diffstat (limited to 'bridge/zulip/zulip.go')
-rw-r--r-- | bridge/zulip/zulip.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/bridge/zulip/zulip.go b/bridge/zulip/zulip.go index e66558a2..c912b6f0 100644 --- a/bridge/zulip/zulip.go +++ b/bridge/zulip/zulip.go @@ -2,6 +2,7 @@ package bzulip import ( "encoding/json" + "fmt" "io/ioutil" "strconv" "strings" @@ -11,6 +12,7 @@ import ( "github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/helper" + "github.com/42wim/matterbridge/version" gzb "github.com/matterbridge/gozulipbot" ) @@ -27,7 +29,7 @@ func New(cfg *bridge.Config) bridge.Bridger { } func (b *Bzulip) Connect() error { - bot := gzb.Bot{APIKey: b.GetString("token"), APIURL: b.GetString("server") + "/api/v1/", Email: b.GetString("login")} + bot := gzb.Bot{APIKey: b.GetString("token"), APIURL: b.GetString("server") + "/api/v1/", Email: b.GetString("login"), UserAgent: fmt.Sprintf("matterbridge/%s", version.Release)} bot.Init() q, err := bot.RegisterAll() b.q = q @@ -125,6 +127,7 @@ func (b *Bzulip) handleQueue() error { b.Log.Debug("heartbeat received.") default: b.Log.Debugf("receiving error: %#v", err) + time.Sleep(time.Second * 10) } if err != nil { continue |