Skip to content

Commit

Permalink
feat(github): retry CreateStatus (#1543)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jian Zeng committed Dec 30, 2020
1 parent 44d6205 commit a793e99
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/server/biz/scm/github/github.go
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/caicloud/cyclone/pkg/server/apis/v1alpha1"
"github.com/caicloud/cyclone/pkg/server/biz/scm"
"github.com/caicloud/cyclone/pkg/util/cerr"
"github.com/caicloud/cyclone/pkg/util/retry"
)

const (
Expand Down Expand Up @@ -408,8 +409,13 @@ func (g *Github) CreateStatus(status c_v1alpha1.StatusPhase, targetURL, repoURL,
Context: &context,
Creator: &creator,
}
_, _, err = client.Repositories.CreateStatus(g.ctx, owner, repo, commitSHA, repoStatus)
return err
return retry.OnError(retry.DefaultRetry, func() error {
_, _, err := client.Repositories.CreateStatus(g.ctx, owner, repo, commitSHA, repoStatus)
if err != nil {
log.V(log.LevelDebug).Infof("Failed to create github status: %v. Will retry. owner=%s, repo=%s, commit=%s", err, owner, repo, commitSHA)
}
return err
})
}

// GetPullRequestSHA gets latest commit SHA of pull request.
Expand Down
9 changes: 9 additions & 0 deletions pkg/util/retry/retry.go
Expand Up @@ -2,11 +2,20 @@ package retry

import (
"strings"
"time"

"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/wait"
)

// DefaultRetry is used to retry github operations now.
var DefaultRetry = wait.Backoff{
Steps: 5,
Duration: 10 * time.Millisecond,
Factor: 3.0,
Jitter: 0.1,
}

// OnError executes the provided function repeatedly, retrying if the server returns an error.
func OnError(backoff wait.Backoff, fn func() error) error {
var lastErr error
Expand Down

0 comments on commit a793e99

Please sign in to comment.