Skip to content

Commit 04b0379

Browse files
authored
feat: add last used to Workspaces page (#3816)
1 parent 80e9f24 commit 04b0379

File tree

20 files changed

+156
-11
lines changed

20 files changed

+156
-11
lines changed

agent/agent_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestAgent(t *testing.T) {
105105
var ok bool
106106
s, ok = (<-stats)
107107
return ok && s.NumConns > 0 && s.RxBytes > 0 && s.TxBytes > 0
108-
}, testutil.WaitShort, testutil.IntervalFast,
108+
}, testutil.WaitLong, testutil.IntervalFast,
109109
"never saw stats: %+v", s,
110110
)
111111
})

coderd/database/databasefake/databasefake.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,6 +2208,22 @@ func (q *fakeQuerier) UpdateWorkspaceTTL(_ context.Context, arg database.UpdateW
22082208
return sql.ErrNoRows
22092209
}
22102210

2211+
func (q *fakeQuerier) UpdateWorkspaceLastUsedAt(_ context.Context, arg database.UpdateWorkspaceLastUsedAtParams) error {
2212+
q.mutex.Lock()
2213+
defer q.mutex.Unlock()
2214+
2215+
for index, workspace := range q.workspaces {
2216+
if workspace.ID != arg.ID {
2217+
continue
2218+
}
2219+
workspace.LastUsedAt = arg.LastUsedAt
2220+
q.workspaces[index] = workspace
2221+
return nil
2222+
}
2223+
2224+
return sql.ErrNoRows
2225+
}
2226+
22112227
func (q *fakeQuerier) UpdateWorkspaceBuildByID(_ context.Context, arg database.UpdateWorkspaceBuildByIDParams) error {
22122228
q.mutex.Lock()
22132229
defer q.mutex.Unlock()

coderd/database/dump.sql

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE workspaces
2+
DROP COLUMN last_used_at;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE workspaces
2+
ADD COLUMN last_used_at timestamp NOT NULL DEFAULT '0001-01-01 00:00:00+00:00';

coderd/database/models.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/querier.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 31 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaces.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,11 @@ SET
137137
ttl = $2
138138
WHERE
139139
id = $1;
140+
141+
-- name: UpdateWorkspaceLastUsedAt :exec
142+
UPDATE
143+
workspaces
144+
SET
145+
last_used_at = $2
146+
WHERE
147+
id = $1;

coderd/templates_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,10 @@ func TestTemplateDAUs(t *testing.T) {
608608
Entries: []codersdk.DAUEntry{},
609609
}, daus, "no DAUs when stats are empty")
610610

611+
workspaces, err := client.Workspaces(ctx, codersdk.WorkspaceFilter{})
612+
require.NoError(t, err)
613+
assert.Zero(t, workspaces[0].LastUsedAt)
614+
611615
conn, err := client.DialWorkspaceAgent(ctx, resources[0].Agents[0].ID, opts)
612616
require.NoError(t, err)
613617
defer func() {
@@ -641,4 +645,10 @@ func TestTemplateDAUs(t *testing.T) {
641645
testutil.WaitShort, testutil.IntervalFast,
642646
"got %+v != %+v", daus, want,
643647
)
648+
649+
workspaces, err = client.Workspaces(ctx, codersdk.WorkspaceFilter{})
650+
require.NoError(t, err)
651+
assert.WithinDuration(t,
652+
time.Now(), workspaces[0].LastUsedAt, time.Minute,
653+
)
644654
}

0 commit comments

Comments
 (0)