github.com/schwarzm/garden-linux@v0.0.0-20150507151835-33bca2147c47/old/repository_fetcher/retryable.go (about)

     1  package repository_fetcher
     2  
     3  import (
     4  	"net/url"
     5  
     6  	"github.com/cloudfoundry-incubator/garden-linux/process"
     7  	"github.com/pivotal-golang/lager"
     8  )
     9  
    10  type Retryable struct {
    11  	RepositoryFetcher
    12  }
    13  
    14  func (retryable Retryable) Fetch(logger lager.Logger, repoName *url.URL, tag string) (string, process.Env, []string, error) {
    15  	var res string
    16  	var err error
    17  	var envvars process.Env
    18  	var volumes []string
    19  
    20  	for attempt := 1; attempt <= 3; attempt++ {
    21  		res, envvars, volumes, err = retryable.RepositoryFetcher.Fetch(logger, repoName, tag)
    22  		if err == nil {
    23  			break
    24  		}
    25  
    26  		logger.Error("failed-to-fetch", err, lager.Data{
    27  			"attempt": attempt,
    28  			"of":      3,
    29  		})
    30  	}
    31  
    32  	return res, envvars, volumes, err
    33  }