Skip to content

Commit

Permalink
fix: handle rate limit skymavis (#1258)
Browse files Browse the repository at this point in the history
  • Loading branch information
trkhoi authored Nov 30, 2023
1 parent 2688797 commit 2f54a6f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pkg/service/birdeye/birdeye.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ var (
)

func (b *birdeye) GetTokenPrice(address string) (*TokenPrice, error) {
b.logger.Debug("start skymavis.GetAddressFarming()")
defer b.logger.Debug("end skymavis.GetAddressFarming()")
b.logger.Debug("start birdeye.GetTokenPrice()")
defer b.logger.Debug("end birdeye.GetTokenPrice()")

var data TokenPrice
// check if data cached
Expand Down
22 changes: 14 additions & 8 deletions pkg/service/skymavis/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,20 @@ func (s *skymavis) doNetworkFarming(address string) (*response.WalletFarmingResp
return nil, err
}
if status != 200 {
s.logger.Fields(logger.Fields{"status": status}).Error(err, "[skymavis.GetAddressFarming] failed to query")
s.sentry.CaptureErrorEvent(sentrygo.SentryCapturePayload{
Message: fmt.Sprintf("[API mochi] - Skymavis - GetAddressFarming failed %v", err),
Tags: sentryTags,
Extra: map[string]interface{}{
"address": address,
},
})
if status == 429 {
s.logger.Fields(logger.Fields{"address": address, "status": status}).Error(err, "[skymavis.GetAddressFarming] reach Skymavis API rate limit, retrying")
time.Sleep(3 * time.Second)
return s.doNetworkFarming(address)
} else {
s.logger.Fields(logger.Fields{"status": status}).Error(err, "[skymavis.GetAddressFarming] failed to query")
s.sentry.CaptureErrorEvent(sentrygo.SentryCapturePayload{
Message: fmt.Sprintf("[API mochi] - Skymavis - GetAddressFarming failed %v", err),
Tags: sentryTags,
Extra: map[string]interface{}{
"address": address,
},
})
}
return nil, err
}

Expand Down

0 comments on commit 2f54a6f

Please sign in to comment.