mirror of
https://github.com/craigerl/aprsd.git
synced 2024-11-18 06:11:49 -05:00
Added try except blocks in collectors
This patch adds some try except blocks in both the stats collector and the packets collector calls to registered objects. This can prevent the rest of APRSD falling down when the collector objects have a failure of some sort.
This commit is contained in:
parent
27359d61aa
commit
88d26241f5
@ -1,9 +1,13 @@
|
||||
import logging
|
||||
from typing import Callable, Protocol, runtime_checkable
|
||||
|
||||
from aprsd.packets import core
|
||||
from aprsd.utils import singleton
|
||||
|
||||
|
||||
LOG = logging.getLogger("APRSD")
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class PacketMonitor(Protocol):
|
||||
"""Protocol for Monitoring packets in some way."""
|
||||
@ -29,7 +33,11 @@ class PacketCollector:
|
||||
for name in self.monitors:
|
||||
cls = name()
|
||||
if isinstance(cls, PacketMonitor):
|
||||
cls.rx(packet)
|
||||
try:
|
||||
cls.rx(packet)
|
||||
except Exception as e:
|
||||
LOG.error(f"Error in monitor {name} (rx): {e}")
|
||||
|
||||
else:
|
||||
raise TypeError(f"Monitor {name} is not a PacketMonitor")
|
||||
|
||||
@ -37,6 +45,9 @@ class PacketCollector:
|
||||
for name in self.monitors:
|
||||
cls = name()
|
||||
if isinstance(cls, PacketMonitor):
|
||||
cls.tx(packet)
|
||||
try:
|
||||
cls.tx(packet)
|
||||
except Exception as e:
|
||||
LOG.error(f"Error in monitor {name} (tx): {e}")
|
||||
else:
|
||||
raise TypeError(f"Monitor {name} is not a PacketMonitor")
|
||||
|
@ -1,8 +1,12 @@
|
||||
import logging
|
||||
from typing import Callable, Protocol, runtime_checkable
|
||||
|
||||
from aprsd.utils import singleton
|
||||
|
||||
|
||||
LOG = logging.getLogger("APRSD")
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class StatsProducer(Protocol):
|
||||
"""The StatsProducer protocol is used to define the interface for collecting stats."""
|
||||
@ -22,7 +26,10 @@ class Collector:
|
||||
for name in self.producers:
|
||||
cls = name()
|
||||
if isinstance(cls, StatsProducer):
|
||||
stats[cls.__class__.__name__] = cls.stats(serializable=serializable)
|
||||
try:
|
||||
stats[cls.__class__.__name__] = cls.stats(serializable=serializable)
|
||||
except Exception as e:
|
||||
LOG.error(f"Error in producer {name} (stats): {e}")
|
||||
else:
|
||||
raise TypeError(f"{cls} is not an instance of StatsProducer")
|
||||
return stats
|
||||
|
Loading…
Reference in New Issue
Block a user