feat: allow removing deadline for running workspace (#16085)

Fixes https://github.com/coder/coder/issues/9775

When a workspace's TTL is removed, and the workspace is running, the
deadline is removed from the workspace.

This also modifies the frontend to not show a confirmation dialog when
the change is to remove autostop.
This commit is contained in:
Danielle Maywood
2025-01-13 21:37:57 +00:00
committed by GitHub
parent 048a10a318
commit 7c595e2631
4 changed files with 114 additions and 32 deletions

View File

@ -1029,6 +1029,26 @@ func (api *API) putWorkspaceTTL(rw http.ResponseWriter, r *http.Request) {
return xerrors.Errorf("update workspace time until shutdown: %w", err)
}
// If autostop has been disabled, we want to remove the deadline from the
// existing workspace build (if there is one).
if !dbTTL.Valid {
build, err := s.GetLatestWorkspaceBuildByWorkspaceID(ctx, workspace.ID)
if err != nil {
return xerrors.Errorf("get latest workspace build: %w", err)
}
if build.Transition == database.WorkspaceTransitionStart {
if err = s.UpdateWorkspaceBuildDeadlineByID(ctx, database.UpdateWorkspaceBuildDeadlineByIDParams{
ID: build.ID,
Deadline: time.Time{},
MaxDeadline: build.MaxDeadline,
UpdatedAt: dbtime.Time(api.Clock.Now()),
}); err != nil {
return xerrors.Errorf("update workspace build deadline: %w", err)
}
}
}
return nil
}, nil)
if err != nil {