mirror of
https://github.com/craigerl/aprsd.git
synced 2025-04-10 05:28:58 -04:00
syncronize the add for StatsStore
This commit is contained in:
parent
f59b65d13c
commit
026dc6e376
@ -62,6 +62,7 @@ class PacketList(objectstore.ObjectStoreMixin):
|
||||
self.data["packets"].popitem(last=False)
|
||||
self.data["packets"][packet.key] = packet
|
||||
|
||||
@wrapt.synchronized(lock)
|
||||
def copy(self):
|
||||
return self.data.copy()
|
||||
|
||||
@ -73,6 +74,7 @@ class PacketList(objectstore.ObjectStoreMixin):
|
||||
def find(self, packet):
|
||||
return self.data["packets"][packet.key]
|
||||
|
||||
@wrapt.synchronized(lock)
|
||||
def __len__(self):
|
||||
return len(self.data["packets"])
|
||||
|
||||
|
@ -3,6 +3,7 @@ import threading
|
||||
import time
|
||||
|
||||
from oslo_config import cfg
|
||||
import wrapt
|
||||
|
||||
from aprsd.stats import collector
|
||||
from aprsd.threads import APRSDThread
|
||||
@ -18,6 +19,10 @@ class StatsStore(objectstore.ObjectStoreMixin):
|
||||
lock = threading.Lock()
|
||||
data = {}
|
||||
|
||||
@wrapt.synchronized(lock)
|
||||
def add(self, stats: dict):
|
||||
self.data = stats
|
||||
|
||||
|
||||
class APRSDStatsStoreThread(APRSDThread):
|
||||
"""Save APRSD Stats to disk periodically."""
|
||||
@ -32,7 +37,7 @@ class APRSDStatsStoreThread(APRSDThread):
|
||||
if self.loop_count % self.save_interval == 0:
|
||||
stats = collector.Collector().collect()
|
||||
ss = StatsStore()
|
||||
ss.data = stats
|
||||
ss.add(stats)
|
||||
ss.save()
|
||||
|
||||
time.sleep(1)
|
||||
|
@ -70,8 +70,8 @@ class ObjectStoreMixin:
|
||||
"""Save any queued to disk?"""
|
||||
if not CONF.enable_save:
|
||||
return
|
||||
save_filename = self._save_filename()
|
||||
if len(self) > 0:
|
||||
save_filename = self._save_filename()
|
||||
LOG.info(
|
||||
f"{self.__class__.__name__}::Saving"
|
||||
f" {len(self)} entries to disk at "
|
||||
@ -83,7 +83,7 @@ class ObjectStoreMixin:
|
||||
LOG.debug(
|
||||
"{} Nothing to save, flushing old save file '{}'".format(
|
||||
self.__class__.__name__,
|
||||
self._save_filename(),
|
||||
save_filename,
|
||||
),
|
||||
)
|
||||
self.flush()
|
||||
|
Loading…
Reference in New Issue
Block a user