Skip to content

Commit

Permalink
was in master, but not in v3
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Jan 14, 2024
1 parent efa5108 commit 0c08205
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (s *Session) getChannels(ctx context.Context, chanTypes []string, cb func(t
nextcur string
)
reqStart := time.Now()
if err := withRetry(ctx, limiter, s.cfg.limits.Tier3.Retries, func() error {
if err := network.WithRetry(ctx, limiter, s.cfg.limits.Tier3.Retries, func() error {
var err error
trace.WithRegion(ctx, "GetConversationsContext", func() {
chans, nextcur, err = s.client.GetConversationsContext(ctx, params)
Expand Down
4 changes: 2 additions & 2 deletions messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (s *Session) dumpChannel(ctx context.Context, channelID string, oldest, lat
resp *slack.GetConversationHistoryResponse
)
reqStart := time.Now()
if err := withRetry(ctx, convLimiter, s.cfg.limits.Tier3.Retries, func() error {
if err := network.WithRetry(ctx, convLimiter, s.cfg.limits.Tier3.Retries, func() error {
var err error
trace.WithRegion(ctx, "GetConversationHistoryContext", func() {
resp, err = s.client.GetConversationHistoryContext(ctx, &slack.GetConversationHistoryParameters{
Expand Down Expand Up @@ -168,7 +168,7 @@ func (s *Session) dumpChannel(ctx context.Context, channelID string, oldest, lat
func (s *Session) getChannelName(ctx context.Context, l *rate.Limiter, channelID string) (string, error) {
// get channel name
var ci *slack.Channel
if err := withRetry(ctx, l, s.cfg.limits.Tier3.Retries, func() error {
if err := network.WithRetry(ctx, l, s.cfg.limits.Tier3.Retries, func() error {
var err error
ci, err = s.client.GetConversationInfoContext(ctx, &slack.GetConversationInfoInput{ChannelID: channelID})
return err
Expand Down
9 changes: 2 additions & 7 deletions slackdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,14 @@ func (s *Session) limiter(t network.Tier) *rate.Limiter {
tl = s.cfg.limits.Tier2
case network.Tier3:
tl = s.cfg.limits.Tier3
case network.Tier4:
tl = s.cfg.limits.Tier4
default:
tl = s.cfg.limits.Tier3
}
return network.NewLimiter(t, tl.Burst, int(tl.Boost)) // BUG: tier was always 3, should fix in master too.
}

// withRetry will run the callback function fn. If the function returns
// slack.RateLimitedError, it will delay, and then call it again up to
// maxAttempts times. It will return an error if it runs out of attempts.
func withRetry(ctx context.Context, l *rate.Limiter, maxAttempts int, fn func() error) error {
return network.WithRetry(ctx, l, maxAttempts, fn)
}

// Info returns a workspace information. Slackdump retrieves workspace
// information during the initialisation when performing authentication test,
// so no API call is involved at this point.
Expand Down
2 changes: 1 addition & 1 deletion thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (s *Session) dumpThread(
nextCursor string
)
reqStart := time.Now()
if err := withRetry(ctx, l, s.cfg.limits.Tier3.Retries, func() error {
if err := network.WithRetry(ctx, l, s.cfg.limits.Tier3.Retries, func() error {
var err error
trace.WithRegion(ctx, "GetConversationRepliesContext", func() {
msgs, hasmore, nextCursor, err = s.client.GetConversationRepliesContext(
Expand Down
2 changes: 1 addition & 1 deletion users.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s *Session) fetchUsers(ctx context.Context) (types.Users, error) {
l := network.NewLimiter(
network.Tier2, s.cfg.limits.Tier2.Burst, int(s.cfg.limits.Tier2.Boost),
)
if err := withRetry(ctx, l, s.cfg.limits.Tier2.Retries, func() error {
if err := network.WithRetry(ctx, l, s.cfg.limits.Tier2.Retries, func() error {
var err error
users, err = s.client.GetUsersContext(ctx)
return err
Expand Down

0 comments on commit 0c08205

Please sign in to comment.