Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: cancel pending prebuilds from non-active template versions#20387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ssncferreira merged 23 commits intomainfromssncferreira/feat-cancel-pending-prebuilds
Oct 24, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
23 commits
Select commitHold shift + click to select a range
ed0e3ab
feat: cancel pending prebuilds on template publish
ssncferreiraOct 20, 2025
29cc88e
test: add cancel pending prebuilds to template version active version
ssncferreiraOct 21, 2025
51fa3ef
chore: minor fixes
ssncferreiraOct 21, 2025
4d677f0
chore: remove pending prebuild job cancellation from template promote…
ssncferreiraOct 22, 2025
836ba0f
fix: SQL query formatting
ssncferreiraOct 22, 2025
5ffe5b2
Merge remote-tracking branch 'origin/main' into ssncferreira/feat-can…
ssncferreiraOct 22, 2025
fac079e
chore: move pending prebuilds cancellation logic to reconciliation loop
ssncferreiraOct 22, 2025
2ce4b7f
fix: minor fixes
ssncferreiraOct 22, 2025
95825cb
fix: minor fixes
ssncferreiraOct 22, 2025
095dd80
Merge remote-tracking branch 'origin/main' into ssncferreira/feat-can…
ssncferreiraOct 22, 2025
d4a7dba
test: add prebuilds tests
ssncferreiraOct 23, 2025
dbb79f3
Merge remote-tracking branch 'origin/main' into ssncferreira/feat-can…
ssncferreiraOct 23, 2025
8ea986e
chore: fix duplicate name test
ssncferreiraOct 23, 2025
0224665
chore: fix imports
ssncferreiraOct 23, 2025
dcb6de1
fix: UpdatePrebuildProvisionerJobWithCancel permissions
ssncferreiraOct 23, 2025
0497f8b
fix: UpdatePrebuildProvisionerJobWithCancel to filter by non-active t…
ssncferreiraOct 23, 2025
b635573
Merge remote-tracking branch 'origin/main' into ssncferreira/feat-can…
ssncferreiraOct 23, 2025
73bfb29
test: add test with different templates and versions
ssncferreiraOct 23, 2025
4bf9eac
Merge remote-tracking branch 'origin/main' into ssncferreira/feat-can…
ssncferreiraOct 23, 2025
629fd74
fix: remove println
ssncferreiraOct 23, 2025
5f81412
fix: remove unused import
ssncferreiraOct 23, 2025
6f2333e
Merge remote-tracking branch 'origin/main' into ssncferreira/feat-can…
ssncferreiraOct 24, 2025
5a52ea9
fix: prebuilds.sql lint
ssncferreiraOct 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletionscoderd/database/dbauthz/dbauthz.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1512,6 +1512,13 @@ func (q *querier) CountInProgressPrebuilds(ctx context.Context) ([]database.Coun
return q.db.CountInProgressPrebuilds(ctx)
}

func (q *querier) CountPendingNonActivePrebuilds(ctx context.Context) ([]database.CountPendingNonActivePrebuildsRow, error) {
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceWorkspace.All()); err != nil {
return nil, err
}
return q.db.CountPendingNonActivePrebuilds(ctx)
}

func (q *querier) CountUnreadInboxNotificationsByUserID(ctx context.Context, userID uuid.UUID) (int64, error) {
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceInboxNotification.WithOwner(userID.String())); err != nil {
return 0, err
Expand DownExpand Up@@ -4875,6 +4882,14 @@ func (q *querier) UpdateOrganizationDeletedByID(ctx context.Context, arg databas
return deleteQ(q.log, q.auth, q.db.GetOrganizationByID, deleteF)(ctx, arg.ID)
}

func (q *querier) UpdatePrebuildProvisionerJobWithCancel(ctx context.Context, arg database.UpdatePrebuildProvisionerJobWithCancelParams) ([]uuid.UUID, error) {
// Prebuild operation for canceling pending prebuild jobs from non-active template versions
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourcePrebuiltWorkspace); err != nil {
return []uuid.UUID{}, err
}
return q.db.UpdatePrebuildProvisionerJobWithCancel(ctx, arg)
}

func (q *querier) UpdatePresetPrebuildStatus(ctx context.Context, arg database.UpdatePresetPrebuildStatusParams) error {
preset, err := q.db.GetPresetByID(ctx, arg.PresetID)
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletionscoderd/database/dbauthz/dbauthz_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -641,6 +641,16 @@ func (s *MethodTestSuite) TestProvisionerJob() {
dbm.EXPECT().UpdateProvisionerJobWithCancelByID(gomock.Any(), arg).Return(nil).AnyTimes()
check.Args(arg).Asserts(v.RBACObject(tpl), []policy.Action{policy.ActionRead, policy.ActionUpdate}).Returns()
}))
s.Run("UpdatePrebuildProvisionerJobWithCancel", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) {
arg := database.UpdatePrebuildProvisionerJobWithCancelParams{
PresetID: uuid.NullUUID{UUID: uuid.New(), Valid: true},
Now: dbtime.Now(),
}
jobIDs := []uuid.UUID{uuid.New(), uuid.New()}

dbm.EXPECT().UpdatePrebuildProvisionerJobWithCancel(gomock.Any(), arg).Return(jobIDs, nil).AnyTimes()
check.Args(arg).Asserts(rbac.ResourcePrebuiltWorkspace, policy.ActionUpdate).Returns(jobIDs)
}))
s.Run("GetProvisionerJobsByIDs", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) {
org := testutil.Fake(s.T(), faker, database.Organization{})
org2 := testutil.Fake(s.T(), faker, database.Organization{})
Expand DownExpand Up@@ -3758,6 +3768,10 @@ func (s *MethodTestSuite) TestPrebuilds() {
dbm.EXPECT().CountInProgressPrebuilds(gomock.Any()).Return([]database.CountInProgressPrebuildsRow{}, nil).AnyTimes()
check.Args().Asserts(rbac.ResourceWorkspace.All(), policy.ActionRead)
}))
s.Run("CountPendingNonActivePrebuilds", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) {
dbm.EXPECT().CountPendingNonActivePrebuilds(gomock.Any()).Return([]database.CountPendingNonActivePrebuildsRow{}, nil).AnyTimes()
check.Args().Asserts(rbac.ResourceWorkspace.All(), policy.ActionRead)
}))
s.Run("GetPresetsAtFailureLimit", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) {
dbm.EXPECT().GetPresetsAtFailureLimit(gomock.Any(), int64(0)).Return([]database.GetPresetsAtFailureLimitRow{}, nil).AnyTimes()
check.Args(int64(0)).Asserts(rbac.ResourceTemplate.All(), policy.ActionViewInsights)
Expand Down
49 changes: 40 additions & 9 deletionscoderd/database/dbfake/dbfake.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -55,14 +55,10 @@ type WorkspaceBuildBuilder struct {
resources []*sdkproto.Resource
params []database.WorkspaceBuildParameter
agentTokenstring
dispoworkspaceBuildDisposition
jobStatus database.ProvisionerJobStatus
taskAppID uuid.UUID
}

typeworkspaceBuildDispositionstruct {
startingbool
}

// WorkspaceBuild generates a workspace build for the provided workspace.
// Pass a database.Workspace{} with a nil ID to also generate a new workspace.
// Omitting the template ID on a workspace will also generate a new template
Expand DownExpand Up@@ -145,8 +141,17 @@ func (b WorkspaceBuildBuilder) WithTask(seed *sdkproto.App) WorkspaceBuildBuilde
}

func (bWorkspaceBuildBuilder)Starting()WorkspaceBuildBuilder {
//nolint: revive // returns modified struct
b.dispo.starting=true
b.jobStatus=database.ProvisionerJobStatusRunning
returnb
}

func (bWorkspaceBuildBuilder)Pending()WorkspaceBuildBuilder {
b.jobStatus=database.ProvisionerJobStatusPending
returnb
}

func (bWorkspaceBuildBuilder)Canceled()WorkspaceBuildBuilder {
b.jobStatus=database.ProvisionerJobStatusCanceled
returnb
}

Expand DownExpand Up@@ -231,7 +236,11 @@ func (b WorkspaceBuildBuilder) Do() WorkspaceResponse {
require.NoError(b.t,err,"insert job")
b.logger.Debug(context.Background(),"inserted provisioner job",slog.F("job_id",job.ID))

ifb.dispo.starting {
switchb.jobStatus {
casedatabase.ProvisionerJobStatusPending:
// Provisioner jobs are created in 'pending' status
b.logger.Debug(context.Background(),"pending the provisioner job")
casedatabase.ProvisionerJobStatusRunning:
// might need to do this multiple times if we got a template version
// import job as well
b.logger.Debug(context.Background(),"looping to acquire provisioner job")
Expand All@@ -255,7 +264,23 @@ func (b WorkspaceBuildBuilder) Do() WorkspaceResponse {
break
}
}
}else {
casedatabase.ProvisionerJobStatusCanceled:
// Set provisioner job status to 'canceled'
b.logger.Debug(context.Background(),"canceling the provisioner job")
err=b.db.UpdateProvisionerJobWithCancelByID(ownerCtx, database.UpdateProvisionerJobWithCancelByIDParams{
ID:jobID,
CanceledAt: sql.NullTime{
Time:dbtime.Now(),
Valid:true,
},
CompletedAt: sql.NullTime{
Time:dbtime.Now(),
Valid:true,
},
})
require.NoError(b.t,err,"cancel job")
default:
// By default, consider jobs in 'succeeded' status
b.logger.Debug(context.Background(),"completing the provisioner job")
err=b.db.UpdateProvisionerJobWithCompleteByID(ownerCtx, database.UpdateProvisionerJobWithCompleteByIDParams{
ID:job.ID,
Expand DownExpand Up@@ -571,6 +596,12 @@ func (t TemplateVersionBuilder) Do() TemplateVersionResponse {
t.params[i]=dbgen.TemplateVersionParameter(t.t,t.db,param)
}

// Update response with template and version
ifresp.Template.ID==uuid.Nil&&version.TemplateID.Valid {
template,err:=t.db.GetTemplateByID(ownerCtx,version.TemplateID.UUID)
require.NoError(t.t,err)
resp.Template=template
}
resp.TemplateVersion=version
returnresp
}
Expand Down
14 changes: 14 additions & 0 deletionscoderd/database/dbmetrics/querymetrics.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

30 changes: 30 additions & 0 deletionscoderd/database/dbmock/dbmock.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

8 changes: 7 additions & 1 deletioncoderd/database/querier.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

113 changes: 112 additions & 1 deletioncoderd/database/queries.sql.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp