mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-07-03 18:46:58 +00: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:
parent
8e658c135d
commit
bbbb53b9bc
@ -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
|
// Fetch pipeline config from source forge
|
||||||
func (cf *configFetcher) Fetch(ctx context.Context) (files []*remote.FileMeta, err error) {
|
func (cf *configFetcher) Fetch(ctx context.Context) (files []*remote.FileMeta, err error) {
|
||||||
log.Trace().Msgf("Start Fetching config for '%s'", cf.repo.FullName)
|
log.Trace().Msgf("Start Fetching config for '%s'", cf.repo.FullName)
|
||||||
|
|
||||||
// try to fetch 3 times, timeout is one second longer each time
|
// try to fetch 3 times, timeout is one second longer each time
|
||||||
for i := 0; i < 3; i++ {
|
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) {
|
if errors.Is(err, context.DeadlineExceeded) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -45,7 +48,7 @@ func (cf *configFetcher) Fetch(ctx context.Context) (files []*remote.FileMeta, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fetch config by timeout
|
// 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) {
|
func (cf *configFetcher) fetch(c context.Context, timeout time.Duration, config string) ([]*remote.FileMeta, error) {
|
||||||
ctx, cancel := context.WithTimeout(c, timeout)
|
ctx, cancel := context.WithTimeout(c, timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
Loading…
Reference in New Issue
Block a user