mirror of
https://github.com/craigerl/aprsd.git
synced 2024-12-19 16:15:57 -05:00
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!
This commit is contained in:
parent
28f3daf6d0
commit
af0d4491c3
@ -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):
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user