Skip to content

Commit

Permalink
fix: webhook race condition on build creation v2 (#191)
Browse files Browse the repository at this point in the history
* fix: decrement webhook retry limit to 3

* fix: skip webhook retry on compile failures

* fix: add error check for getting new build
  • Loading branch information
jbrockopp authored Oct 5, 2020
1 parent f0b0ea3 commit 744a34f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions api/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func PostWebhook(c *gin.Context) {
// variable to store pipeline
var p *pipeline.Build
// number of times to retry
retryLimit := 5
retryLimit := 3

// iterate through with a retryLimit
for i := 0; i < retryLimit; i++ {
Expand Down Expand Up @@ -402,12 +402,6 @@ func PostWebhook(c *gin.Context) {
// log the error for traceability
logrus.Error(err.Error())

// check if the retry limit has been exceeded
if i < retryLimit {
// continue to the next iteration of the loop
continue
}

retErr := fmt.Errorf("%s: %v", baseErr, err)
util.HandleError(c, http.StatusInternalServerError, retErr)

Expand Down Expand Up @@ -443,7 +437,14 @@ func PostWebhook(c *gin.Context) {
}

// send API call to capture the triggered build
b, _ = database.FromContext(c).GetBuild(b.GetNumber(), r)
b, err = database.FromContext(c).GetBuild(b.GetNumber(), r)
if err != nil {
retErr := fmt.Errorf("%s: failed to get new build %s/%d: %v", baseErr, r.GetFullName(), b.GetNumber(), err)
util.HandleError(c, http.StatusInternalServerError, retErr)

h.SetStatus(constants.StatusFailure)
h.SetError(retErr.Error())
}

// set the BuildID field
h.SetBuildID(b.GetID())
Expand Down

0 comments on commit 744a34f

Please sign in to comment.