use a backoff when fetching the yaml

This commit is contained in:
Brad Rydzewski 2017-12-01 09:22:30 -08:00
parent 6397395570
commit 970080e444
2 changed files with 16 additions and 1 deletions

View file

@ -154,3 +154,18 @@ func Refresh(c context.Context, u *model.User) (bool, error) {
}
return refresher.Refresh(u)
}
// FileBackoff fetches the file using an exponential backoff.
// TODO replace this with a proper backoff
func FileBackoff(remote Remote, u *model.User, r *model.Repo, b *model.Build, f string) (out []byte, err error) {
for i := 0; i < 5; i++ {
select {
case <-time.After(time.Second * time.Duration(i)):
out, err = remote.File(u, r, b, f)
if err == nil {
return
}
}
}
return
}

View file

@ -143,7 +143,7 @@ func PostHook(c *gin.Context) {
}
// fetch the build file from the database
confb, err := remote_.File(user, repo, build, repo.Config)
confb, err := remote.FileBackoff(remote_, user, repo, build, repo.Config)
if err != nil {
logrus.Errorf("error: %s: cannot find %s in %s: %s", repo.FullName, repo.Config, build.Ref, err)
c.AbortWithError(404, err)