From 73df1e4061c8ad5c839810add85861bffa1404cb Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Thu, 21 Sep 2023 00:30:17 +0200 Subject: [PATCH] fixed the device-flushing interval not being const --- server/backend/device.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/server/backend/device.go b/server/backend/device.go index 0250f4e7..3ab3068b 100644 --- a/server/backend/device.go +++ b/server/backend/device.go @@ -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") }