fix(cli): port-forward: update workspace last_used_at (#12659)

This PR updates the coder port-forward command to periodically inform coderd that the workspace is being used:

- Adds workspaceusage.Tracker which periodically batch-updates workspace LastUsedAt
- Adds coderd endpoint to signal workspace usage
- Updates coder port-forward to periodically hit this endpoint
- Modifies BatchUpdateWorkspacesLastUsedAt to avoid overwriting with stale data

Co-authored-by: Danny Kopping <danny@coder.com>
This commit is contained in:
Cian Johnston
2024-03-20 16:44:12 +00:00
committed by GitHub
parent d789a60d47
commit 92aa1eba97
15 changed files with 708 additions and 2 deletions

View File

@ -433,7 +433,10 @@ UPDATE
SET
last_used_at = @last_used_at
WHERE
id = ANY(@ids :: uuid[]);
id = ANY(@ids :: uuid[])
AND
-- Do not overwrite with older data
last_used_at < @last_used_at;
-- name: GetDeploymentWorkspaceStats :one
WITH workspaces_with_jobs AS (