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))
| 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. |
| 93 | func (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 |
no test coverage detected