From 0521074bc7552d9680d29bee9a2762f3e6a05bca Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Wed, 17 May 2023 20:45:21 -0500 Subject: [PATCH 1/3] feat: Add queue Item.ItemVersion field This should allow the worker to invalidate stale queued builds. A stale build is a build that was queued before a Vela upgrade or downgrade if the two Vela versions do not share the same queue ItemVersion. --- item.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/item.go b/item.go index 14a2c117..cae3619d 100644 --- a/item.go +++ b/item.go @@ -9,20 +9,29 @@ import ( "github.com/go-vela/types/pipeline" ) +// ItemVersion allows the worker to detect items that were queued before an Vela server +// upgrade or downgrade, so it can handle such stale data gracefully. +// For example, the worker could fail a stale build or ask the server to recompile it. +// This is not a public API and is unrelated to the version key in pipeline yaml. +const ItemVersion uint64 = 1 + // Item is the queue representation of an item to publish to the queue. type Item struct { Build *library.Build `json:"build"` Pipeline *pipeline.Build `json:"pipeline"` Repo *library.Repo `json:"repo"` User *library.User `json:"user"` + // The 0-value is the implicit ItemVersion for queued Items that pre-date adding the field. + ItemVersion uint64 `json:"version"` } // ToItem creates a queue item from a pipeline, build, repo and user. func ToItem(p *pipeline.Build, b *library.Build, r *library.Repo, u *library.User) *Item { return &Item{ - Pipeline: p, - Build: b, - Repo: r, - User: u, + Pipeline: p, + Build: b, + Repo: r, + User: u, + ItemVersion: ItemVersion, } } From 82336d8f725bb17ad8c8d0c5bc32c2d5f4d456b0 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Wed, 17 May 2023 20:55:51 -0500 Subject: [PATCH 2/3] refactor: adjust ToItem test to handle new ItemVersion field --- item_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/item_test.go b/item_test.go index 603ef388..ebb9e78b 100644 --- a/item_test.go +++ b/item_test.go @@ -159,6 +159,7 @@ func TestTypes_ToItem(t *testing.T) { Active: &booL, Admin: &booL, }, + ItemVersion: ItemVersion, } // run test From ba495f9ec7722c392809075f9562535bb09d8da9 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Wed, 17 May 2023 20:58:58 -0500 Subject: [PATCH 3/3] refactor: rename json key to item_version from just version Make it clear that this is not the Vela version or the pipeline yaml version. --- item.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/item.go b/item.go index cae3619d..972d4c97 100644 --- a/item.go +++ b/item.go @@ -22,7 +22,7 @@ type Item struct { Repo *library.Repo `json:"repo"` User *library.User `json:"user"` // The 0-value is the implicit ItemVersion for queued Items that pre-date adding the field. - ItemVersion uint64 `json:"version"` + ItemVersion uint64 `json:"item_version"` } // ToItem creates a queue item from a pipeline, build, repo and user.