From af0d4491c39bec3a8837c90b14db80b4e4c8c45b Mon Sep 17 00:00:00 2001 From: Hemna Date: Wed, 30 Dec 2020 09:10:28 -0500 Subject: [PATCH] Added QueryPlugin resend all delayed msgs or Flush This patch also updates the QueryPlugin to allow the configured user to immediately resend all Delayed messages! This patch updates the QueryPlugin to allow the configured user to immediately Flush/delete all messages! --- aprsd/messaging.py | 21 ++++++++++++++++++--- aprsd/plugin.py | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/aprsd/messaging.py b/aprsd/messaging.py index 043e599..32229e0 100644 --- a/aprsd/messaging.py +++ b/aprsd/messaging.py @@ -88,8 +88,10 @@ class MsgTrack(object): def save(self): """Save this shit to disk?""" if len(self) > 0: - LOG.info("Need to save tracking to disk") + LOG.info("Saving {} tracking messages to disk".format(len(self))) pickle.dump(self.dump(), open(utils.DEFAULT_SAVE_FILE, "wb+")) + else: + self.flush() def dump(self): dump = {} @@ -109,13 +111,26 @@ class MsgTrack(object): def restart(self): """Walk the list of messages and restart them if any.""" + for key in self.track.keys(): msg = self.track[key] - msg.send() + if msg.last_send_attempt < msg.retry_count: + msg.send() + + def restart_delayed(self): + """Walk the list of delayed messages and restart them if any.""" + for key in self.track.keys(): + msg = self.track[key] + if msg.last_send_attempt == msg.retry_count: + msg.last_send_attempt = 0 + msg.send() def flush(self): """Nuke the old pickle file that stored the old results from last aprsd run.""" - pathlib.Path(utils.DEFAULT_SAVE_FILE).unlink() + if os.path.exists(utils.DEFAULT_SAVE_FILE): + pathlib.Path(utils.DEFAULT_SAVE_FILE).unlink() + with self.lock: + self.track = {} class MessageCounter(object): diff --git a/aprsd/plugin.py b/aprsd/plugin.py index 9e69103..8a1b4f8 100644 --- a/aprsd/plugin.py +++ b/aprsd/plugin.py @@ -367,6 +367,27 @@ class QueryPlugin(APRSDPluginBase): tracker = messaging.MsgTrack() reply = "Pending Messages ({})".format(len(tracker)) + searchstring = "^" + self.config["ham"]["callsign"] + ".*" + # only I can do admin commands + if re.search(searchstring, fromcall): + r = re.search(r"^\?-\*", message) + if r is not None: + if len(tracker) > 0: + reply = "Resend ALL Delayed msgs" + LOG.debug(reply) + tracker.restart_delayed() + else: + reply = "No Delayed Msgs" + LOG.debug(reply) + return reply + + r = re.search(r"^\?-[fF]!", message) + if r is not None: + reply = "Deleting ALL Delayed msgs." + LOG.debug(reply) + tracker.flush() + return reply + return reply