mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: implement fake DeleteOldWorkspaceAgentStats (#11076)
This commit is contained in:
@@ -1180,8 +1180,22 @@ func (q *FakeQuerier) DeleteOldWorkspaceAgentLogs(_ context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (*FakeQuerier) DeleteOldWorkspaceAgentStats(_ context.Context) error {
|
||||
// no-op
|
||||
func (q *FakeQuerier) DeleteOldWorkspaceAgentStats(_ context.Context) error {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
now := dbtime.Now()
|
||||
sixMonthInterval := 6 * 30 * 24 * time.Hour
|
||||
sixMonthsAgo := now.Add(-sixMonthInterval)
|
||||
|
||||
var validStats []database.WorkspaceAgentStat
|
||||
for _, stat := range q.workspaceAgentStats {
|
||||
if stat.CreatedAt.Before(sixMonthsAgo) {
|
||||
continue
|
||||
}
|
||||
validStats = append(validStats, stat)
|
||||
}
|
||||
q.workspaceAgentStats = validStats
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user