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