aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/github
diff options
context:
space:
mode:
authorAlexander Scharinger <rng.dynamics@gmail.com>2021-03-09 15:31:58 +0100
committerAlexander Scharinger <rng.dynamics@gmail.com>2021-03-15 08:39:08 +0100
commitd7f555b4374eee2ecdc144283a73327c931f09f1 (patch)
tree7072bb05fc8862a66362d9f8ec45821bc951f29f /bridge/github
parent93b14c509b8260d8238ec1b32394b4a03bcd1349 (diff)
downloadgit-bug-d7f555b4374eee2ecdc144283a73327c931f09f1.tar.gz
Github bridge: try again in case of web API error
Diffstat (limited to 'bridge/github')
-rw-r--r--bridge/github/import_mediator.go24
1 files changed, 23 insertions, 1 deletions
diff --git a/bridge/github/import_mediator.go b/bridge/github/import_mediator.go
index 02067286..8d1796b0 100644
--- a/bridge/github/import_mediator.go
+++ b/bridge/github/import_mediator.go
@@ -359,8 +359,30 @@ type rateLimiter interface {
// and it is used to populate the response into it. It should be a pointer to a struct that
// corresponds to the Github graphql schema and it has to implement the rateLimiter interface. If
// there is a Github rate limiting error, then the function sleeps and retries after the rate limit
-// is expired.
+// is expired. If there is another error, then the method will retry before giving up.
func (mm *importMediator) mQuery(ctx context.Context, query rateLimiter, vars map[string]interface{}) error {
+ if err := mm.queryOnce(ctx, query, vars); err == nil {
+ // success: done
+ return nil
+ }
+ // failure: we will retry
+ // This is important for importing projects with a big number of issues.
+ retries := 3
+ var err error
+ for i := 0; i < retries; i++ {
+ // wait a few seconds before retry
+ sleepTime := 8 * (i + 1)
+ time.Sleep(time.Duration(sleepTime) * time.Second)
+ err = mm.queryOnce(ctx, query, vars)
+ if err == nil {
+ // success: done
+ return nil
+ }
+ }
+ return err
+}
+
+func (mm *importMediator) queryOnce(ctx context.Context, query rateLimiter, vars map[string]interface{}) error {
// first: just send the query to the graphql api
vars["dryRun"] = githubv4.Boolean(false)
qctx, cancel := context.WithTimeout(ctx, defaultTimeout)