mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add API/SDK support for autostop extension (#1778)
* Adds deadline column to workspace_builds, associated DB/API plumbing * database: Upon inserting a row into workspace_builds, deadline will initially be zero. * autobuild: Executor now checks the Deadline field of the workspace_build for the purpose of autostop logic. * coderd: Adds a new route /api/v2/workspaces/:workspace/extend which allows updating the deadline of the currently active workspace build. The new deadline must be after the existing deadline, and not the zero time. * provisionerd: updates workspace_build.deadline upon successful workspace build completion (equal to now plus workspace TTL, if it exists).
This commit is contained in:
@@ -177,6 +177,26 @@ func (c *Client) UpdateWorkspaceTTL(ctx context.Context, id uuid.UUID, req Updat
|
||||
return nil
|
||||
}
|
||||
|
||||
// PutExtendWorkspaceRequest is a request to extend the deadline of
|
||||
// the active workspace build.
|
||||
type PutExtendWorkspaceRequest struct {
|
||||
Deadline time.Time `json:"deadline" validate:"required"`
|
||||
}
|
||||
|
||||
// PutExtendWorkspace updates the deadline for resources of the latest workspace build.
|
||||
func (c *Client) PutExtendWorkspace(ctx context.Context, id uuid.UUID, req PutExtendWorkspaceRequest) error {
|
||||
path := fmt.Sprintf("/api/v2/workspaces/%s/extend", id.String())
|
||||
res, err := c.Request(ctx, http.MethodPut, path, req)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("extend workspace ttl: %w", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusNotModified {
|
||||
return readBodyAsError(res)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type WorkspaceFilter struct {
|
||||
OrganizationID uuid.UUID
|
||||
// Owner can be a user_id (uuid), "me", or a username
|
||||
|
||||
Reference in New Issue
Block a user