From 8529f1f8d1a4a86a66aecfda6e6075c394bbff56 Mon Sep 17 00:00:00 2001 From: Hemna Date: Tue, 26 Nov 2024 12:35:36 -0500 Subject: [PATCH] Updated keepalive thread to report client This patch updates the keepalive thread and the aprsis client and kiss client to report keepalive. --- aprsd/client/aprsis.py | 2 +- aprsd/client/kiss.py | 14 ++++++++++++-- aprsd/threads/keep_alive.py | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/aprsd/client/aprsis.py b/aprsd/client/aprsis.py index d9b79bd..d6ad9ec 100644 --- a/aprsd/client/aprsis.py +++ b/aprsd/client/aprsis.py @@ -38,7 +38,7 @@ class APRSISClient(base.APRSClient): "connected": self.is_connected, "filter": self.filter, "login_status": self.login_status, - "server_keepalive": keepalive, + "connection_keepalive": keepalive, "server_string": server_string, "transport": self.transport(), } diff --git a/aprsd/client/kiss.py b/aprsd/client/kiss.py index 988060b..d413aa1 100644 --- a/aprsd/client/kiss.py +++ b/aprsd/client/kiss.py @@ -1,3 +1,4 @@ +import datetime import logging import aprslib @@ -16,12 +17,17 @@ LOG = logging.getLogger("APRSD") class KISSClient(base.APRSClient): _client = None + keepalive = datetime.datetime.now() def stats(self, serializable=False) -> dict: stats = {} if self.is_configured(): + keepalive = self.keepalive + if serializable: + keepalive = keepalive.isoformat() stats = { "connected": self.is_connected, + "connection_keepalive": keepalive, "transport": self.transport(), } if self.transport() == client.TRANSPORT_TCPKISS: @@ -110,5 +116,9 @@ class KISSClient(base.APRSClient): return self._client def consumer(self, callback, blocking=False, immortal=False, raw=False): - LOG.info(f"{self.__class__.__name__}.consumer called") - self._client.consumer(callback) + try: + self._client.consumer(callback) + self.keepalive = datetime.datetime.now() + except Exception as ex: + LOG.error(f"Consumer failed {ex}") + LOG.error(ex) diff --git a/aprsd/threads/keep_alive.py b/aprsd/threads/keep_alive.py index 886406e..a47e4a5 100644 --- a/aprsd/threads/keep_alive.py +++ b/aprsd/threads/keep_alive.py @@ -100,7 +100,7 @@ class KeepAliveThread(APRSDThread): # check the APRS connection cl = client_factory.create() cl_stats = cl.stats() - ka = cl_stats.get("keepalive", None) + ka = cl_stats.get("connection_keepalive", None) if ka: keepalive = timeago.format(ka) else: