Skip to content

Commit

Permalink
Track retry count
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbsh committed Nov 5, 2019
1 parent 19dc613 commit 66c4cc6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion main.go
Expand Up @@ -61,13 +61,15 @@ var policy = backoff.NewExponential(
func getBranch(ctx context.Context, client *github.Client, repoOrg string, repoName string, branchName string) (*github.Branch, *github.Response, error) {
b, cancel := policy.Start(context.Background())
defer cancel()
retries := 0
//Use backoff for rety logic because Repositories.GetBranch sometimes returns 404s if the repo is slow to create
for backoff.Continue(b) {
branch, response, err := client.Repositories.GetBranch(ctx, repoOrg, repoName, branchName)
if err == nil && response.StatusCode == 200 && branch != nil{
return branch, response, err
}
log.Printf("Retrying getBranch for %s", branchName)
retries++
log.Printf("Retrying (%v) getBranch for %s in repo %s", retries, branchName, repoName)
}

return nil, nil, errors.New("Failed to find branch")
Expand Down

0 comments on commit 66c4cc6

Please sign in to comment.