forked from ALHP/ALHP.GO
retry regardless of error, add retry limit
This commit is contained in:
@@ -5,6 +5,8 @@ repos:
|
|||||||
|
|
||||||
state_repo: "https://gitlab.archlinux.org/archlinux/packaging/state.git"
|
state_repo: "https://gitlab.archlinux.org/archlinux/packaging/state.git"
|
||||||
|
|
||||||
|
max_clone_retries: 100
|
||||||
|
|
||||||
db:
|
db:
|
||||||
driver: pgx
|
driver: pgx
|
||||||
connect_to: "postgres://username:password@localhost:5432/database_name"
|
connect_to: "postgres://username:password@localhost:5432/database_name"
|
||||||
|
@@ -337,19 +337,16 @@ func (p *ProtoPackage) setupBuildDir() (string, error) {
|
|||||||
gitlabPath = reReplaceUnderscore.ReplaceAllString(gitlabPath, "-")
|
gitlabPath = reReplaceUnderscore.ReplaceAllString(gitlabPath, "-")
|
||||||
gitlabPath = reReplaceTree.ReplaceAllString(gitlabPath, "unix-tree")
|
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,
|
cmd := exec.Command("git", "clone", "--depth", "1", "--branch", p.State.TagVer,
|
||||||
fmt.Sprintf("https://gitlab.archlinux.org/archlinux/packaging/packages/%s.git", gitlabPath), buildDir)
|
fmt.Sprintf("https://gitlab.archlinux.org/archlinux/packaging/packages/%s.git", gitlabPath), buildDir)
|
||||||
res, err := cmd.CombinedOutput()
|
res, err := cmd.CombinedOutput()
|
||||||
log.Debug(string(res))
|
log.Debug(string(res))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gitHTTPMatch := reGitHTTPError.FindAllStringSubmatch(string(res), -1)
|
return retry.RetryableError(err)
|
||||||
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 nil
|
return nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
2
utils.go
2
utils.go
@@ -50,7 +50,6 @@ var (
|
|||||||
reReplaceSpecialChars = regexp.MustCompile(`(?m)[^a-zA-Z0-9_\-.]`)
|
reReplaceSpecialChars = regexp.MustCompile(`(?m)[^a-zA-Z0-9_\-.]`)
|
||||||
reReplaceUnderscore = regexp.MustCompile(`(?m)[_\-]{2,}`)
|
reReplaceUnderscore = regexp.MustCompile(`(?m)[_\-]{2,}`)
|
||||||
reReplaceTree = regexp.MustCompile(`(?m)^tree$`)
|
reReplaceTree = regexp.MustCompile(`(?m)^tree$`)
|
||||||
reGitHTTPError = regexp.MustCompile(`(?mi)The requested URL returned error: (\d+)`)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Conf struct {
|
type Conf struct {
|
||||||
@@ -84,6 +83,7 @@ type Conf struct {
|
|||||||
Skipped, Queued, Latest, Failed, Signing, Building, Unknown string
|
Skipped, Queued, Latest, Failed, Signing, Building, Unknown string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MaxCloneRetries uint64 `yaml:"max_clone_retries"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Globs []string
|
type Globs []string
|
||||||
|
Reference in New Issue
Block a user