mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
chore(coderd/database/dbpurge): replace usage of time.* with quartz (#14480)
Related to #10576 This PR introduces quartz to coderd/database/dbpurge and updates the following unit tests to make use of Quartz's functionality: - TestPurge - TestDeleteOldWorkspaceAgentLogs Additionally, updates DeleteOldWorkspaceAgentLogs to replace the hard-coded interval with a parameter passed into the query. This aids in testing and brings us a step towards allowing operators to configure the cutoff interval for workspace agent logs.
This commit is contained in:
@ -1706,19 +1706,15 @@ func (q *FakeQuerier) DeleteOldProvisionerDaemons(_ context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *FakeQuerier) DeleteOldWorkspaceAgentLogs(_ context.Context) error {
|
||||
func (q *FakeQuerier) DeleteOldWorkspaceAgentLogs(_ context.Context, threshold time.Time) 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) {
|
||||
if agent.ID == log.AgentID && agent.LastConnectedAt.Valid && agent.LastConnectedAt.Time.Before(threshold) {
|
||||
toBeDeleted = true
|
||||
break
|
||||
}
|
||||
|
Reference in New Issue
Block a user