Skip to content

Commit fef8176

Browse files
committed
chore: only send 1 job event for canceled pending prebuilds
1 parent f161c82 commit fef8176

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

enterprise/coderd/prebuilds/reconcile.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,8 @@ func (c *StoreReconciler) provisionDelete(ctx context.Context, db database.Store
788788
// Since these jobs were never processed by a provisioner, no Terraform resources were created,
789789
// making it safe to orphan-delete the workspaces (skipping Terraform destroy).
790790
func (c *StoreReconciler) cancelAndOrphanDeletePendingPrebuilds(ctx context.Context, templateID uuid.UUID, templateVersionID uuid.UUID, presetID uuid.UUID) error {
791-
provisionerJobs := make(map[uuid.UUID]*database.ProvisionerJob)
791+
var canceledProvisionerJob *database.ProvisionerJob
792+
var canceledWorkspaceID uuid.UUID
792793
err := c.store.InTx(func(db database.Store) error {
793794
canceledJobs, err := db.UpdatePrebuildProvisionerJobWithCancel(
794795
ctx,
@@ -823,8 +824,9 @@ func (c *StoreReconciler) cancelAndOrphanDeletePendingPrebuilds(ctx context.Cont
823824
c.logger.Error(ctx, "failed to orphan delete canceled prebuild",
824825
slog.F("workspace_id", job.WorkspaceID.String()), slog.Error(err))
825826
multiErr.Errors = append(multiErr.Errors, err)
826-
} else {
827-
provisionerJobs[job.WorkspaceID] = provisionerJob
827+
} else if canceledProvisionerJob == nil {
828+
canceledProvisionerJob = provisionerJob
829+
canceledWorkspaceID = job.WorkspaceID
828830
}
829831
}
830832

@@ -837,9 +839,12 @@ func (c *StoreReconciler) cancelAndOrphanDeletePendingPrebuilds(ctx context.Cont
837839
return err
838840
}
839841

840-
// Publish provisioner job events to notify the acquirer that new jobs were posted
841-
for workspaceID, job := range provisionerJobs {
842-
c.publishProvisionerJob(ctx, job, workspaceID)
842+
// Job event notifications contain organization, provisioner type, and tags.
843+
// Since all canceled jobs have the same values, we only send one notification
844+
// for the first successfully canceled job, which is sufficient to trigger the
845+
// provisioner chain that processes all remaining jobs.
846+
if canceledProvisionerJob != nil {
847+
c.publishProvisionerJob(ctx, canceledProvisionerJob, canceledWorkspaceID)
843848
}
844849

845850
return nil

0 commit comments

Comments
 (0)