Skip to content

Commit

Permalink
Merge branch 'main' into feature/prometeus-based-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm authored Sep 21, 2023
2 parents fdd8624 + 73df1e4 commit 9a28844
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions server/backend/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,22 @@ import (

// deviceBuffer stores all recent device calls in a buffer and flushes them to the database periodically
type deviceBuffer struct {
lock sync.Mutex
devices map[string]*model.Devices // key is uuid
interval time.Duration // flush interval
lock sync.Mutex
devices map[string]*model.Devices // key is uuid
}

func newDeviceBuffer() *deviceBuffer {
return &deviceBuffer{
lock: sync.Mutex{},
devices: make(map[string]*model.Devices),
interval: time.Minute,
lock: sync.Mutex{},
devices: make(map[string]*model.Devices),
}

}

const FlushingInterval = time.Minute

func (s *CampusServer) RunDeviceFlusher() error {
for {
time.Sleep(s.deviceBuf.interval)
time.Sleep(FlushingInterval)
if err := s.deviceBuf.flush(s.db); err != nil {
log.WithError(err).Error("Error flushing device buffer")
}
Expand Down

0 comments on commit 9a28844

Please sign in to comment.