Skip to content

Commit

Permalink
Retry loading messages page
Browse files Browse the repository at this point in the history
Seems sometimes we get errors parsing the output that a simple retry
fixes.
  • Loading branch information
Fizzadar committed Feb 20, 2025
1 parent 8232e9a commit 5c28b6a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ func (m *MetaClient) getProxy(reason string) (string, error) {
return respData.ProxyURL, nil
}

var ConnectRetries = 3

func (m *MetaClient) Connect(ctx context.Context) {
if !m.connectLock.TryLock() {
zerolog.Ctx(ctx).Error().Msg("Connect called multiple times in parallel")
Expand Down Expand Up @@ -166,7 +168,7 @@ func (m *MetaClient) connectWithRetry(ctx context.Context, attempts int) {
return
}
}
currentUser, initialTable, err := m.Client.LoadMessagesPage()
currentUser, initialTable, err := m.Client.LoadMessagesPageWithRetries(ConnectRetries)
if err != nil {
zerolog.Ctx(ctx).Err(err).Msg("Failed to load messages page")
if stopPeriodicReconnect := m.stopPeriodicReconnect.Swap(nil); stopPeriodicReconnect != nil {
Expand Down
12 changes: 12 additions & 0 deletions pkg/messagix/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ func NewClient(cookies *cookies.Cookies, logger zerolog.Logger) *Client {
return cli
}

func (c *Client) LoadMessagesPageWithRetries(retries int) (info types.UserInfo, table *table.LSTable, err error) {
for i := range retries {
info, table, err = c.LoadMessagesPage()
if err == nil {
return
}
c.Logger.Warn().Err(err).Msgf("Failed to load messages page, retrying in %ds", retries)
time.Sleep(time.Second * time.Duration(i))
}
return
}

func (c *Client) LoadMessagesPage() (types.UserInfo, *table.LSTable, error) {
if c == nil {
return nil, nil, ErrClientIsNil
Expand Down

0 comments on commit 5c28b6a

Please sign in to comment.