From 36757dc711a6b9a7ad4bcda5ccec149f42680f88 Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Tue, 23 May 2023 21:51:37 +0200 Subject: [PATCH] retry regardless of error, add retry limit --- config_dist.yaml | 2 ++ proto_package.go | 13 +++++-------- utils.go | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/config_dist.yaml b/config_dist.yaml index e4308ab..7ed94e5 100644 --- a/config_dist.yaml +++ b/config_dist.yaml @@ -5,6 +5,8 @@ repos: state_repo: "https://gitlab.archlinux.org/archlinux/packaging/state.git" +max_clone_retries: 100 + db: driver: pgx connect_to: "postgres://username:password@localhost:5432/database_name" diff --git a/proto_package.go b/proto_package.go index 862d934..b347afc 100644 --- a/proto_package.go +++ b/proto_package.go @@ -337,19 +337,16 @@ func (p *ProtoPackage) setupBuildDir() (string, error) { gitlabPath = reReplaceUnderscore.ReplaceAllString(gitlabPath, "-") gitlabPath = reReplaceTree.ReplaceAllString(gitlabPath, "unix-tree") - if err := retry.Fibonacci(context.Background(), 10*time.Second, func(ctx context.Context) error { + gr := retry.NewFibonacci(10 * time.Second) + gr = retry.WithMaxRetries(conf.MaxCloneRetries, gr) + + if err := retry.Do(context.Background(), gr, func(ctx context.Context) error { cmd := exec.Command("git", "clone", "--depth", "1", "--branch", p.State.TagVer, fmt.Sprintf("https://gitlab.archlinux.org/archlinux/packaging/packages/%s.git", gitlabPath), buildDir) res, err := cmd.CombinedOutput() log.Debug(string(res)) if err != nil { - gitHTTPMatch := reGitHTTPError.FindAllStringSubmatch(string(res), -1) - if len(gitHTTPMatch) > 0 && gitHTTPMatch[0][1] == "429" { - log.Infof("unable to clone %s->%s repo, trying again later", p.March, p.Pkgbase) - return retry.RetryableError(err) - } else { - return fmt.Errorf("git clone failed: %s", string(res)) - } + return retry.RetryableError(err) } return nil }); err != nil { diff --git a/utils.go b/utils.go index 6b62b6d..c7ce3ed 100644 --- a/utils.go +++ b/utils.go @@ -50,7 +50,6 @@ var ( reReplaceSpecialChars = regexp.MustCompile(`(?m)[^a-zA-Z0-9_\-.]`) reReplaceUnderscore = regexp.MustCompile(`(?m)[_\-]{2,}`) reReplaceTree = regexp.MustCompile(`(?m)^tree$`) - reGitHTTPError = regexp.MustCompile(`(?mi)The requested URL returned error: (\d+)`) ) type Conf struct { @@ -84,6 +83,7 @@ type Conf struct { Skipped, Queued, Latest, Failed, Signing, Building, Unknown string } } + MaxCloneRetries uint64 `yaml:"max_clone_retries"` } type Globs []string