Skip to content

Commit

Permalink
minor CHORE warn when github secondary rate limit is reached and tell…
Browse files Browse the repository at this point in the history
… about when it will continue (#12)
  • Loading branch information
SlevinWasAlreadyTaken authored Jun 14, 2023
1 parent 8b8ec67 commit a4963e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/github/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ func NewClient(ctx context.Context, ghToken string) (*Client, error) {
tc := oauth2.NewClient(ctx, ts)
// use a rate limiter to handle better the github api limit
// focuses on the secondary limit: https://github.com/google/go-github#rate-limiting
rateLimiter, err := github_ratelimit.NewRateLimitWaiterClient(tc.Transport)
rateLimiter, err := github_ratelimit.NewRateLimitWaiterClient(
tc.Transport,
github_ratelimit.WithLimitDetectedCallback(LogOnLimitDetected),
)
if err != nil {
return nil, err
}
Expand Down
11 changes: 11 additions & 0 deletions internal/github/ratelimit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package github

import (
"gha-file-sync/internal/log"

"github.com/gofri/go-github-ratelimit/github_ratelimit"
)

func LogOnLimitDetected(ctx *github_ratelimit.CallbackContext) {
log.Warnf("secondary rate limit detected, will continue at %v", ctx.SleepUntil)
}

0 comments on commit a4963e8

Please sign in to comment.