keep last notified timestamp in memory
All checks were successful
dreamfall/clacksme/pipeline/head This commit looks good

This commit is contained in:
Morgan McMillian 2022-12-30 13:12:33 -08:00
parent ba12e2c5ba
commit 57af4f3c8d

View file

@ -16,6 +16,7 @@ class MailboxNotifier(object):
def __init__(self, mailbox): def __init__(self, mailbox):
self.mailbox = mailbox self.mailbox = mailbox
self.last_check = mailbox.last_check
def start(self, log_queue, event_queue): def start(self, log_queue, event_queue):
imap_log = logging.getLogger('imapclient') imap_log = logging.getLogger('imapclient')
@ -78,12 +79,11 @@ class MailboxNotifier(object):
self.log.info("New message") self.log.info("New message")
now = datetime.now() now = datetime.now()
self.event_queue.put({ self.event_queue.put({
"kind": "event", "mailbox": self.mailbox,
"user": self.mailbox.user, "now": now,
"mailbox": self.mailbox.imap_user,
"event_id": uid}) "event_id": uid})
if self.mailbox.last_check is not None: if self.last_check is not None:
delta = now - self.mailbox.last_check delta = now - self.last_check
if delta.seconds > 60: if delta.seconds > 60:
notify = True notify = True
else: else:
@ -91,10 +91,7 @@ class MailboxNotifier(object):
if notify: if notify:
self.log.debug("Notify") self.log.debug("Notify")
self.event_queue.put({ self.last_check = now
"kind": "notify",
"uid": self.mailbox.id,
"now": now})
self.on_notify() self.on_notify()
def on_notify(self): def on_notify(self):
@ -151,14 +148,12 @@ def event_thread(event_queue):
while not _shutdown.is_set(): while not _shutdown.is_set():
entry = event_queue.get() entry = event_queue.get()
if entry is not None: if entry is not None:
if entry['kind'] == "event": mailbox = entry['mailbox']
new_event = Events( new_event = Events(
user=entry['user'], user=mailbox.user,
mailbox=entry['mailbox'], mailbox=mailbox.imap_user,
event_id=entry['event_id']) event_id=entry['event_id'])
new_event.save() new_event.save()
elif entry['kind'] == "notify":
mailbox = Mailbox.get(id=entry['uid'])
mailbox.last_check = entry['now'] mailbox.last_check = entry['now']
mailbox.save() mailbox.save()
else: else: