diff --git a/pkg/server/biz/scm/github/github.go b/pkg/server/biz/scm/github/github.go index fc824bea9..9c9309109 100644 --- a/pkg/server/biz/scm/github/github.go +++ b/pkg/server/biz/scm/github/github.go @@ -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 ( @@ -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. diff --git a/pkg/util/retry/retry.go b/pkg/util/retry/retry.go index e9243ef57..b2e9620a2 100644 --- a/pkg/util/retry/retry.go +++ b/pkg/util/retry/retry.go @@ -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