Skip to content

Commit

Permalink
enhance(exec): do not kill worker if build has been canceled and buil…
Browse files Browse the repository at this point in the history
…d token minting fails (#472)

* enhance(exec): do not kill worker if build has been canceled and build token minting fails

* change status code to 409 conflict

* upgrade server
  • Loading branch information
ecrupper authored May 10, 2023
1 parent c764655 commit 4116724
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
12 changes: 10 additions & 2 deletions cmd/vela-worker/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main

import (
"context"
"net/http"
"sync"
"time"

Expand All @@ -19,7 +20,7 @@ import (
// exec is a helper function to poll the queue
// and execute Vela pipelines for the Worker.
//
//nolint:nilerr // ignore returning nil - don't want to crash worker
//nolint:nilerr,funlen // ignore returning nil - don't want to crash worker
func (w *Worker) exec(index int) error {
var err error

Expand All @@ -37,9 +38,16 @@ func (w *Worker) exec(index int) error {
}

// retrieve a build token from the server to setup the execBuildClient
bt, _, err := w.VelaClient.Build.GetBuildToken(item.Repo.GetOrg(), item.Repo.GetName(), item.Build.GetNumber())
bt, resp, err := w.VelaClient.Build.GetBuildToken(item.Repo.GetOrg(), item.Repo.GetName(), item.Build.GetNumber())
if err != nil {
logrus.Errorf("unable to retrieve build token: %s", err)

// build is not in pending state — user canceled build while it was in queue. Pop, discard, move on.
if resp != nil && resp.StatusCode == http.StatusConflict {
return nil
}

// something else is amiss (auth, server down, etc.) — shut down worker, will have to re-register if registration enabled.
return err
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/docker/go-units v0.5.0
github.com/gin-gonic/gin v1.9.0
github.com/go-vela/sdk-go v0.19.2
github.com/go-vela/server v0.19.2
github.com/go-vela/server v0.19.3-0.20230510141710-f99a894333d4
github.com/go-vela/types v0.19.2
github.com/golang-jwt/jwt/v5 v5.0.0
github.com/google/go-cmp v0.5.9
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVL
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I=
github.com/go-vela/sdk-go v0.19.2 h1:bEMnEnEZxI27ZCjFx5fNRFc0EYHr2NsR2jb//0J5SJk=
github.com/go-vela/sdk-go v0.19.2/go.mod h1:p0WwKyBLslyhPjSQnA78SVZpLDkOL/P030BtzdRDjtE=
github.com/go-vela/server v0.19.2 h1:b5kQLbQzzY1PQ2/GJN5MHCmlo4wS9C3cyy4fErOl4/o=
github.com/go-vela/server v0.19.2/go.mod h1:N6ej04/c6kc/0sJK15jCLr3Au9L9Zs9TjcMtkJoyJx8=
github.com/go-vela/server v0.19.3-0.20230510141710-f99a894333d4 h1:hAj76WkNt+CZfkionu86xlpM3YpupZkX1OWHzWbeEpA=
github.com/go-vela/server v0.19.3-0.20230510141710-f99a894333d4/go.mod h1:N6ej04/c6kc/0sJK15jCLr3Au9L9Zs9TjcMtkJoyJx8=
github.com/go-vela/types v0.19.2 h1:xU61CX2jdMuBCtLOg8a7Z2aEWYM1zZt37Ygx1oHGbjM=
github.com/go-vela/types v0.19.2/go.mod h1:ZvDjYCKU36yJS3sLxPLCny/HLF1U6YtlOienzv/cXB4=
github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA=
Expand Down

0 comments on commit 4116724

Please sign in to comment.