Files
coder/coderd/workspacestats/workspacestatstest/batcher.go
2024-06-25 10:58:45 -04:00

39 lines
836 B
Go

package workspacestatstest
import (
"sync"
"time"
"github.com/google/uuid"
agentproto "github.com/coder/coder/v2/agent/proto"
"github.com/coder/coder/v2/coderd/workspacestats"
)
type StatsBatcher struct {
Mu sync.Mutex
Called int64
LastTime time.Time
LastAgentID uuid.UUID
LastTemplateID uuid.UUID
LastUserID uuid.UUID
LastWorkspaceID uuid.UUID
LastStats *agentproto.Stats
}
var _ workspacestats.Batcher = &StatsBatcher{}
func (b *StatsBatcher) Add(now time.Time, agentID uuid.UUID, templateID uuid.UUID, userID uuid.UUID, workspaceID uuid.UUID, st *agentproto.Stats) error {
b.Mu.Lock()
defer b.Mu.Unlock()
b.Called++
b.LastTime = now
b.LastAgentID = agentID
b.LastTemplateID = templateID
b.LastUserID = userID
b.LastWorkspaceID = workspaceID
b.LastStats = st
return nil
}