Skip to content

Commit 96299f0

Browse files
committed
use session count to fix test
1 parent b301c40 commit 96299f0

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

coderd/workspacestats/reporter.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,18 @@ func (r *Reporter) ReportAgentStats(ctx context.Context, now time.Time, workspac
153153
}
154154
return nil
155155
})
156-
errGroup.Go(func() error {
157-
// nolint:gocritic // (#13146) Will be moved soon as part of refactor.
158-
err := r.opts.Database.UpdateWorkspaceLastUsedAt(ctx, database.UpdateWorkspaceLastUsedAtParams{
159-
ID: workspace.ID,
160-
LastUsedAt: now,
156+
if sessionCount(stats) > 0 {
157+
errGroup.Go(func() error {
158+
err := r.opts.Database.UpdateWorkspaceLastUsedAt(ctx, database.UpdateWorkspaceLastUsedAtParams{
159+
ID: workspace.ID,
160+
LastUsedAt: now,
161+
})
162+
if err != nil {
163+
return xerrors.Errorf("update workspace LastUsedAt: %w", err)
164+
}
165+
return nil
161166
})
162-
if err != nil {
163-
return xerrors.Errorf("update workspace LastUsedAt: %w", err)
164-
}
165-
return nil
166-
})
167+
}
167168
if r.opts.UpdateAgentMetricsFn != nil {
168169
errGroup.Go(func() error {
169170
user, err := r.opts.Database.GetUserByID(ctx, workspace.OwnerID)
@@ -193,3 +194,7 @@ func (r *Reporter) ReportAgentStats(ctx context.Context, now time.Time, workspac
193194

194195
return nil
195196
}
197+
198+
func sessionCount(s *agentproto.Stats) int64 {
199+
return s.SessionCountVscode + s.SessionCountJetbrains + s.SessionCountReconnectingPty + s.SessionCountSsh
200+
}

0 commit comments

Comments
 (0)