Skip to content

Commit 8987e9e

Browse files
committed
RED: add deadline to workspace builds
1 parent c7dff0e commit 8987e9e

File tree

11 files changed

+43
-25
lines changed

11 files changed

+43
-25
lines changed

coderd/autobuild/executor/lifecycle_executor.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,16 @@ func (e *Executor) runOnce(t time.Time) error {
8888
switch priorHistory.Transition {
8989
case database.WorkspaceTransitionStart:
9090
validTransition = database.WorkspaceTransitionStop
91-
if !ws.Ttl.Valid || ws.Ttl.Int64 == 0 {
92-
e.log.Debug(e.ctx, "invalid or zero ws ttl, skipping",
91+
if priorHistory.Deadline.IsZero() {
92+
e.log.Debug(e.ctx, "latest workspace build has zero deadline, skipping",
9393
slog.F("workspace_id", ws.ID),
94-
slog.F("ttl", time.Duration(ws.Ttl.Int64)),
94+
slog.F("workspace_build_id", priorHistory.ID),
9595
)
9696
continue
9797
}
98-
ttl := time.Duration(ws.Ttl.Int64)
99-
// Measure TTL from the time the workspace finished building.
10098
// Truncate to nearest minute for consistency with autostart
10199
// behavior, and add one minute for padding.
102-
nextTransition = priorHistory.UpdatedAt.Truncate(time.Minute).Add(ttl + time.Minute)
100+
nextTransition = priorHistory.Deadline.Truncate(time.Minute)
103101
case database.WorkspaceTransitionStop:
104102
validTransition = database.WorkspaceTransitionStart
105103
sched, err := schedule.Weekly(ws.AutostartSchedule.String)

coderd/database/databasefake/databasefake.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,7 @@ func (q *fakeQuerier) InsertWorkspaceBuild(_ context.Context, arg database.Inser
14851485
InitiatorID: arg.InitiatorID,
14861486
JobID: arg.JobID,
14871487
ProvisionerState: arg.ProvisionerState,
1488+
Deadline: arg.Deadline,
14881489
}
14891490
q.workspaceBuilds = append(q.workspaceBuilds, workspaceBuild)
14901491
return workspaceBuild, nil

coderd/database/dump.sql

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE ONLY workspace_builds DROP COLUMN deadline;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE ONLY workspace_builds ADD COLUMN deadline TIMESTAMPTZ NOT NULL DEFAULT TIMESTAMPTZ '0001-01-01 00:00:00+00:00';

coderd/database/models.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 18 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspacebuilds.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ INSERT INTO
101101
transition,
102102
initiator_id,
103103
job_id,
104-
provisioner_state
104+
provisioner_state,
105+
deadline
105106
)
106107
VALUES
107-
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING *;
108+
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING *;
108109

109110
-- name: UpdateWorkspaceBuildByID :exec
110111
UPDATE

codersdk/workspacebuilds.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type WorkspaceBuild struct {
3232
Transition WorkspaceTransition `json:"transition"`
3333
InitiatorID uuid.UUID `json:"initiator_id"`
3434
Job ProvisionerJob `json:"job"`
35+
Deadline time.Time `json:"deadline"`
3536
}
3637

3738
// WorkspaceBuild returns a single workspace build for a workspace.

codersdk/workspaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type Workspace struct {
2828
Name string `json:"name"`
2929
AutostartSchedule string `json:"autostart_schedule"`
3030
TTL *time.Duration `json:"ttl"`
31+
Deadline time.Time `json:"deadline"`
3132
}
3233

3334
// CreateWorkspaceBuildRequest provides options to update the latest workspace build.

0 commit comments

Comments
 (0)