MCPcopy Index your code
hub / github.com/coder/coder / putWorkspaceDormant

Method putWorkspaceDormant

coderd/workspaces.go:1444–1604  ·  view source on GitHub ↗

@Summary Update workspace dormancy status by id. @ID update-workspace-dormancy-status-by-id @Security CoderSessionToken @Accept json @Produce json @Tags Workspaces @Param workspace path string true "Workspace ID" format(uuid) @Param request body codersdk.UpdateWorkspaceDormancy true "Make a workspac

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

1442// @Success 200 {object} codersdk.Workspace
1443// @Router /api/v2/workspaces/{workspace}/dormant [put]
1444func (api *API) putWorkspaceDormant(rw http.ResponseWriter, r *http.Request) {
1445 var (
1446 ctx = r.Context()
1447 oldWorkspace = httpmw.WorkspaceParam(r)
1448 apiKey = httpmw.APIKey(r)
1449 auditor = api.Auditor.Load()
1450 aReq, commitAudit = audit.InitRequest[database.WorkspaceTable](rw, &audit.RequestParams{
1451 Audit: *auditor,
1452 Log: api.Logger,
1453 Request: r,
1454 Action: database.AuditActionWrite,
1455 OrganizationID: oldWorkspace.OrganizationID,
1456 })
1457 )
1458 aReq.Old = oldWorkspace.WorkspaceTable()
1459 defer commitAudit()
1460
1461 var req codersdk.UpdateWorkspaceDormancy
1462 if !httpapi.Read(ctx, rw, r, &req) {
1463 return
1464 }
1465
1466 // Dormancy configuration is not supported for prebuilt workspaces.
1467 // Prebuilds are managed by the reconciliation loop and are not subject to dormancy.
1468 if oldWorkspace.IsPrebuild() {
1469 httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{
1470 Message: "Dormancy updates are not supported for prebuilt workspaces",
1471 Detail: "Prebuilt workspaces are not subject to dormancy. Dormancy behavior is only applicable to regular workspaces",
1472 })
1473 return
1474 }
1475
1476 // If the workspace is already in the desired state do nothing!
1477 if oldWorkspace.DormantAt.Valid == req.Dormant {
1478 rw.WriteHeader(http.StatusNotModified)
1479 return
1480 }
1481
1482 // Use injected Clock to allow time mocking in tests
1483 now := api.Clock.Now()
1484
1485 dormantAt := sql.NullTime{
1486 Valid: req.Dormant,
1487 }
1488 if req.Dormant {
1489 dormantAt.Time = dbtime.Time(now)
1490 }
1491
1492 newWorkspace, err := api.Database.UpdateWorkspaceDormantDeletingAt(ctx, database.UpdateWorkspaceDormantDeletingAtParams{
1493 ID: oldWorkspace.ID,
1494 DormantAt: dormantAt,
1495 })
1496 if err != nil {
1497 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
1498 Message: "Internal error updating workspace locked status.",
1499 Detail: err.Error(),
1500 })
1501 return

Callers

nothing calls this directly

Calls 15

workspaceDataMethod · 0.95
WorkspaceParamFunction · 0.92
APIKeyFunction · 0.92
InitRequestFunction · 0.92
ReadFunction · 0.92
WriteFunction · 0.92
TimeFunction · 0.92
AsNotifierFunction · 0.92
ForbiddenFunction · 0.92
convertWorkspaceFunction · 0.85
WorkspaceTableMethod · 0.80
DurationMethod · 0.80

Tested by

no test coverage detected