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

Method UpdateWorkspaceUsageContext

codersdk/workspaces.go:442–472  ·  view source on GitHub ↗

UpdateWorkspaceUsageContext periodically posts workspace usage for the workspace with the given id in the background. The caller is responsible for calling the returned function to stop the background process. Deprecated: use UpdateWorkspaceUsageContextWithBody instead

(ctx context.Context, workspaceID uuid.UUID)

Source from the content-addressed store, hash-verified

440// process.
441// Deprecated: use UpdateWorkspaceUsageContextWithBody instead
442func (c *Client) UpdateWorkspaceUsageContext(ctx context.Context, workspaceID uuid.UUID) func() {
443 hbCtx, hbCancel := context.WithCancel(ctx)
444 // Perform one initial update
445 err := c.PostWorkspaceUsage(hbCtx, workspaceID)
446 if err != nil {
447 c.logger.Warn(ctx, "failed to post workspace usage", slog.Error(err))
448 }
449 ticker := time.NewTicker(time.Minute)
450 doneCh := make(chan struct{})
451 go func() {
452 defer func() {
453 ticker.Stop()
454 close(doneCh)
455 }()
456 for {
457 select {
458 case <-ticker.C:
459 err := c.PostWorkspaceUsage(hbCtx, workspaceID)
460 if err != nil {
461 c.logger.Warn(ctx, "failed to post workspace usage in background", slog.Error(err))
462 }
463 case <-hbCtx.Done():
464 return
465 }
466 }
467 }()
468 return func() {
469 hbCancel()
470 <-doneCh
471 }
472}
473
474// UpdateWorkspaceDormancy is a request to activate or make a workspace dormant.
475// A value of false will activate a dormant workspace.

Callers 1

portForwardMethod · 0.80

Calls 4

PostWorkspaceUsageMethod · 0.95
StopMethod · 0.65
ErrorMethod · 0.45
DoneMethod · 0.45

Tested by

no test coverage detected