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

Method UpdateWorkspaceUsageWithBodyContext

codersdk/workspaces.go:405–435  ·  view source on GitHub ↗

UpdateWorkspaceUsageWithBodyContext periodically posts workspace usage for the workspace with the given id and app name in the background. The caller is responsible for calling the returned function to stop the background process.

(ctx context.Context, workspaceID uuid.UUID, req PostWorkspaceUsageRequest)

Source from the content-addressed store, hash-verified

403// The caller is responsible for calling the returned function to stop the background
404// process.
405func (c *Client) UpdateWorkspaceUsageWithBodyContext(ctx context.Context, workspaceID uuid.UUID, req PostWorkspaceUsageRequest) func() {
406 hbCtx, hbCancel := context.WithCancel(ctx)
407 // Perform one initial update
408 err := c.PostWorkspaceUsageWithBody(hbCtx, workspaceID, req)
409 if err != nil {
410 c.logger.Warn(ctx, "failed to post workspace usage", slog.Error(err))
411 }
412 ticker := time.NewTicker(time.Minute)
413 doneCh := make(chan struct{})
414 go func() {
415 defer func() {
416 ticker.Stop()
417 close(doneCh)
418 }()
419 for {
420 select {
421 case <-ticker.C:
422 err := c.PostWorkspaceUsageWithBody(hbCtx, workspaceID, req)
423 if err != nil {
424 c.logger.Warn(ctx, "failed to post workspace usage in background", slog.Error(err))
425 }
426 case <-hbCtx.Done():
427 return
428 }
429 }
430 }()
431 return func() {
432 hbCancel()
433 <-doneCh
434 }
435}
436
437// UpdateWorkspaceUsageContext periodically posts workspace usage for the workspace
438// with the given id in the background.

Callers 3

handleRPTYFunction · 0.80
sshMethod · 0.80
vscodeSSHMethod · 0.80

Calls 4

StopMethod · 0.65
ErrorMethod · 0.45
DoneMethod · 0.45

Tested by

no test coverage detected