Skip to content

Commit 44ea963

Browse files
committed
update autobuild
1 parent f6a08b1 commit 44ea963

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

coderd/autobuild/lifecycle_executor.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (e *Executor) runOnce(t time.Time) Stats {
179179
Reason(reason)
180180
log.Debug(e.ctx, "auto building workspace", slog.F("transition", nextTransition))
181181
if nextTransition == database.WorkspaceTransitionStart &&
182-
ws.AutomaticUpdates == database.AutomaticUpdatesAlways {
182+
useActiveVersion(templateSchedule, ws) {
183183
log.Debug(e.ctx, "autostarting with active version")
184184
builder = builder.ActiveVersion()
185185
}
@@ -458,3 +458,7 @@ func auditBuild(ctx context.Context, log slog.Logger, auditor audit.Auditor, par
458458
AdditionalFields: raw,
459459
})
460460
}
461+
462+
func useActiveVersion(opts schedule.TemplateScheduleOptions, ws database.Workspace) bool {
463+
return opts.RequirePromotedVersion || ws.AutomaticUpdates == database.AutomaticUpdatesAlways
464+
}

coderd/wsbuilder/wsbuilder.go

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"time"
1212

1313
"github.com/google/uuid"
14-
"github.com/lib/pq"
1514
"github.com/sqlc-dev/pqtype"
1615
"golang.org/x/xerrors"
1716

@@ -210,29 +209,17 @@ func (b *Builder) Build(
210209
// RepeatableRead isolation ensures that we get a consistent view of the database while
211210
// computing the new build. This simplifies the logic so that we do not need to worry if
212211
// later reads are consistent with earlier ones.
213-
var err error
214-
for retries := 0; retries < 5; retries++ {
215-
var workspaceBuild *database.WorkspaceBuild
216-
var provisionerJob *database.ProvisionerJob
217-
err := store.InTx(func(store database.Store) error {
218-
b.store = store
219-
workspaceBuild, provisionerJob, err = b.buildTx(authFunc)
220-
return err
221-
}, &sql.TxOptions{Isolation: sql.LevelRepeatableRead})
222-
var pqe *pq.Error
223-
if xerrors.As(err, &pqe) {
224-
if pqe.Code == "40001" {
225-
// serialization error, retry
226-
continue
227-
}
228-
}
229-
if err != nil {
230-
// Other (hard) error
231-
return nil, nil, err
232-
}
233-
return workspaceBuild, provisionerJob, nil
212+
var workspaceBuild *database.WorkspaceBuild
213+
var provisionerJob *database.ProvisionerJob
214+
err := database.ReadModifyUpdate(store, func(tx database.Store) error {
215+
var err error
216+
workspaceBuild, provisionerJob, err = b.buildTx(authFunc)
217+
return err
218+
})
219+
if err != nil {
220+
return nil, nil, xerrors.Errorf("too many errors; last error: %w", err)
234221
}
235-
return nil, nil, xerrors.Errorf("too many errors; last error: %w", err)
222+
return workspaceBuild, provisionerJob, nil
236223
}
237224

238225
// buildTx contains the business logic of computing a new build. Attributes of the new database objects are computed

0 commit comments

Comments
 (0)