1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-11-24 08:02:18 +02:00

Always wait 3s to fetch pipeline config (#458)

This fix a bug where first try will fail because timeout is 0s
This commit is contained in:
6543 2021-10-19 02:04:21 +02:00 committed by GitHub
parent 8e658c135d
commit bbbb53b9bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,13 +29,16 @@ func NewConfigFetcher(remote remote.Remote, user *model.User, repo *model.Repo,
}
}
// configFetchTimeout determine seconds the configFetcher wait until cancel fetch process
var configFetchTimeout = 3 // seconds
// Fetch pipeline config from source forge
func (cf *configFetcher) Fetch(ctx context.Context) (files []*remote.FileMeta, err error) {
log.Trace().Msgf("Start Fetching config for '%s'", cf.repo.FullName)
// try to fetch 3 times, timeout is one second longer each time
for i := 0; i < 3; i++ {
files, err = cf.fetch(ctx, time.Second*time.Duration(i), strings.TrimSpace(cf.repo.Config))
files, err = cf.fetch(ctx, time.Second*time.Duration(configFetchTimeout), strings.TrimSpace(cf.repo.Config))
if errors.Is(err, context.DeadlineExceeded) {
continue
}
@ -45,7 +48,7 @@ func (cf *configFetcher) Fetch(ctx context.Context) (files []*remote.FileMeta, e
}
// fetch config by timeout
// TODO: dedupe code
// TODO: deduplicate code
func (cf *configFetcher) fetch(c context.Context, timeout time.Duration, config string) ([]*remote.FileMeta, error) {
ctx, cancel := context.WithTimeout(c, timeout)
defer cancel()