MCPcopy Index your code
hub / github.com/git-bug/git-bug / callAPIAndRetry

Method callAPIAndRetry

bridge/github/client.go:93–118  ·  view source on GitHub ↗

callAPIAndRetry calls the Github GraphQL API (indirectly through callAPIDealWithLimit) and in case of error it repeats the request to the Github API. The parameter `apiCall` is intended to be a closure containing a query or a mutation to the Github GraphQL API.

(ctx context.Context, apiCall func(context.Context) error, rateLimitEvent func(msg string))

Source from the content-addressed store, hash-verified

91// case of error it repeats the request to the Github API. The parameter `apiCall` is intended to be
92// a closure containing a query or a mutation to the Github GraphQL API.
93func (c *rateLimitHandlerClient) callAPIAndRetry(ctx context.Context, apiCall func(context.Context) error, rateLimitEvent func(msg string)) error {
94 var err error
95 if err = c.callAPIDealWithLimit(ctx, apiCall, rateLimitEvent); err == nil {
96 return nil
97 }
98 // failure; the reason may be temporary network problems or internal errors
99 // on the github servers. Internal errors on the github servers are quite common.
100 // Retry
101 retries := 3
102 for i := 0; i < retries; i++ {
103 // wait a few seconds before retry
104 sleepTime := time.Duration(8*(i+1)) * time.Second
105 timer := time.NewTimer(sleepTime)
106 select {
107 case <-ctx.Done():
108 stop(timer)
109 return ctx.Err()
110 case <-timer.C:
111 err = c.callAPIDealWithLimit(ctx, apiCall, rateLimitEvent)
112 if err == nil {
113 return nil
114 }
115 }
116 }
117 return err
118}
119
120// callAPIDealWithLimit calls the Github GraphQL API and if the Github API returns a rate limiting
121// error, then it waits until the rate limit is reset, and it repeats the request to the API. The

Callers 4

mutateMethod · 0.95
queryImportMethod · 0.95
queryExportMethod · 0.95
queryPrintMsgsMethod · 0.95

Calls 2

callAPIDealWithLimitMethod · 0.95
stopFunction · 0.85

Tested by

no test coverage detected