Skip to content

Commit

Permalink
Merge branch 'main' of github.com:go-vela/worker into feature/schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockopp committed May 25, 2023
2 parents f5ffd66 + 1ff33a7 commit 4cc057b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
24 changes: 23 additions & 1 deletion cmd/vela-worker/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
"sync"
"time"

"github.com/go-vela/types"
"github.com/go-vela/types/constants"
"github.com/go-vela/worker/executor"
"github.com/go-vela/worker/runtime"
"github.com/go-vela/worker/version"

"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -70,6 +71,27 @@ func (w *Worker) exec(index int) error {
"version": v.Semantic(),
})

// handle stale item queued before a Vela upgrade or downgrade.
if item.ItemVersion != types.ItemVersion {
// If the ItemVersion is older or newer than what we expect, then it might
// not be safe to process the build. Fail the build and loop to the next item.
// TODO: Ask the server to re-compile and requeue the build instead of failing it.
logrus.Errorf("Failing stale queued build due to wrong item version: want %d, got %d", types.ItemVersion, item.ItemVersion)

build := item.Build
build.SetError("Unable to process stale build (queued before Vela upgrade/downgrade).")
build.SetStatus(constants.StatusError)
build.SetFinished(time.Now().UTC().Unix())

_, _, err := w.VelaClient.Build.Update(item.Repo.GetOrg(), item.Repo.GetName(), build)
if err != nil {
logrus.Errorf("Unable to set build status to %s: %s", constants.StatusFailure, err)
return err
}

return nil
}

// setup the runtime
//
// https://pkg.go.dev/github.com/go-vela/worker/runtime?tab=doc#New
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/gin-gonic/gin v1.9.0
github.com/go-vela/sdk-go v0.19.3-0.20230525152744-4c6fc715258c
github.com/go-vela/server v0.19.3-0.20230523191014-5a9a92d279e0
github.com/go-vela/types v0.19.3-0.20230519215217-0da8c8b5e90f
github.com/go-vela/types v0.19.3-0.20230523200921-35a0d5fc088c
github.com/golang-jwt/jwt/v5 v5.0.0
github.com/google/go-cmp v0.5.9
github.com/joho/godotenv v1.5.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ github.com/go-vela/sdk-go v0.19.3-0.20230525152744-4c6fc715258c h1:2GV5t+AOyMYIo
github.com/go-vela/sdk-go v0.19.3-0.20230525152744-4c6fc715258c/go.mod h1:0XTE3DHG5B872POEhKJ3kZzL8ZvR1jAJSeakeJgjfCM=
github.com/go-vela/server v0.19.3-0.20230523191014-5a9a92d279e0 h1:jyNJ1YdYj0YBRcwzyab8yZWBjGt543ATp/eftgPZBoA=
github.com/go-vela/server v0.19.3-0.20230523191014-5a9a92d279e0/go.mod h1:sjfqYOyuXG7uqgeQF03URz7GGNjVE+JNIhkGK00eT9o=
github.com/go-vela/types v0.19.3-0.20230519215217-0da8c8b5e90f h1:13H381Djx9iFC3BSj2f/ac57HlaI3mQL0el9vM7a3+k=
github.com/go-vela/types v0.19.3-0.20230519215217-0da8c8b5e90f/go.mod h1:0lsuPfGyVyTWJSi2h3NS6uaEW6DgnFvIzaZu1sXYKrs=
github.com/go-vela/types v0.19.3-0.20230523200921-35a0d5fc088c h1:eAApIK5e5MxFF8RzZAFsvTSdwq/AzdUrdhJHOGQ0ILc=
github.com/go-vela/types v0.19.3-0.20230523200921-35a0d5fc088c/go.mod h1:0lsuPfGyVyTWJSi2h3NS6uaEW6DgnFvIzaZu1sXYKrs=
github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA=
github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
Expand Down

0 comments on commit 4cc057b

Please sign in to comment.