fix: implement fake DeleteOldWorkspaceAgentLogs (#11042)

This commit is contained in:
Marcin Tojek
2023-12-06 14:31:43 +01:00
committed by GitHub
parent 088fd0b904
commit f6891bc465
2 changed files with 141 additions and 5 deletions

View File

@ -1154,8 +1154,29 @@ func (q *FakeQuerier) DeleteOldProvisionerDaemons(_ context.Context) error {
return nil
}
func (*FakeQuerier) DeleteOldWorkspaceAgentLogs(_ context.Context) error {
// no-op
func (q *FakeQuerier) DeleteOldWorkspaceAgentLogs(_ context.Context) error {
q.mutex.Lock()
defer q.mutex.Unlock()
now := dbtime.Now()
weekInterval := 7 * 24 * time.Hour
weekAgo := now.Add(-weekInterval)
var validLogs []database.WorkspaceAgentLog
for _, log := range q.workspaceAgentLogs {
var toBeDeleted bool
for _, agent := range q.workspaceAgents {
if agent.ID == log.AgentID && agent.LastConnectedAt.Valid && agent.LastConnectedAt.Time.Before(weekAgo) {
toBeDeleted = true
break
}
}
if !toBeDeleted {
validLogs = append(validLogs, log)
}
}
q.workspaceAgentLogs = validLogs
return nil
}