ActivityBumpWorkspace automatically bumps the workspace's auto-off timer if it is set to expire soon. The deadline will be bumped by 1 hour*. If the bump crosses over an autostart time, the workspace will be bumped by the workspace ttl instead. If nextAutostart is the zero value or in the past, the
(ctx context.Context, log slog.Logger, db database.Store, workspaceID uuid.UUID, nextAutostart time.Time, reason ActivityBumpReason)
| 52 | // span more than 1 day. This will force the workspace to restart and reset the deadline |
| 53 | // each morning when it autostarts. |
| 54 | func ActivityBumpWorkspace(ctx context.Context, log slog.Logger, db database.Store, workspaceID uuid.UUID, nextAutostart time.Time, reason ActivityBumpReason) { |
| 55 | // We set a short timeout so if the app is under load, these |
| 56 | // low priority operations fail first. |
| 57 | ctx, cancel := context.WithTimeout(ctx, time.Second*15) |
| 58 | defer cancel() |
| 59 | err := db.ActivityBumpWorkspace(ctx, database.ActivityBumpWorkspaceParams{ |
| 60 | NextAutostart: nextAutostart.UTC(), |
| 61 | WorkspaceID: workspaceID, |
| 62 | }) |
| 63 | if err != nil { |
| 64 | if !xerrors.Is(err, context.Canceled) && !database.IsQueryCanceledError(err) { |
| 65 | // Bump will fail if the context is canceled, but this is ok. |
| 66 | log.Error(ctx, "activity bump failed", slog.Error(err), |
| 67 | slog.F("workspace_id", workspaceID), |
| 68 | slog.F("reason", reason), |
| 69 | ) |
| 70 | } |
| 71 | return |
| 72 | } |
| 73 | |
| 74 | log.Debug(ctx, "bumped deadline from activity", |
| 75 | slog.F("workspace_id", workspaceID), |
| 76 | slog.F("reason", reason), |
| 77 | ) |
| 78 | } |