retry regardless of error, add retry limit

This commit is contained in:
Giovanni Harting 2023-05-23 21:51:37 +02:00
parent 025ab9a75a
commit 36757dc711
3 changed files with 8 additions and 9 deletions

View File

@ -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"

View File

@ -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 {

View File

@ -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