add healthcheck service

This commit is contained in:
2024-08-17 01:44:20 +03:00
parent 25762cbae8
commit f635d4ca5b
11 changed files with 422 additions and 15 deletions

View File

@ -0,0 +1,40 @@
package memory
import (
"context"
"sync"
"git.loyso.art/frx/devsim/internal/entities"
)
type store struct {
stats map[entities.DeviceID]entities.DeviceStatistics
mu sync.Mutex
}
func NewStore() *store {
return &store{
stats: make(map[entities.DeviceID]entities.DeviceStatistics),
}
}
func (s *store) List(ctx context.Context) ([]entities.DeviceStatistics, error) {
s.mu.Lock()
defer s.mu.Unlock()
out := make([]entities.DeviceStatistics, 0, len(s.stats))
for _, s := range s.stats {
out = append(out, s)
}
return out, nil
}
func (s *store) Upsert(ctx context.Context, stats entities.DeviceStatistics) error {
s.mu.Lock()
defer s.mu.Unlock()
s.stats[stats.ID] = stats
return nil
}