only alert on invalid mailbox that has too many email logs
This commit is contained in:
parent
77c67c5314
commit
63e228d9f4
|
@ -1528,15 +1528,6 @@ class Mailbox(db.Model, ModelMixin):
|
|||
cls.query.filter(cls.id == obj_id).delete()
|
||||
db.session.commit()
|
||||
|
||||
def nb_email_log(self):
|
||||
return (
|
||||
db.session.query(EmailLog)
|
||||
.join(Contact, EmailLog.contact_id == Contact.id)
|
||||
.join(Alias, Alias.id == Contact.alias_id)
|
||||
.filter(Alias.mailbox_id == self.id)
|
||||
.count()
|
||||
)
|
||||
|
||||
@property
|
||||
def aliases(self) -> [Alias]:
|
||||
ret = Alias.filter_by(mailbox_id=self.id).all()
|
||||
|
|
9
cron.py
9
cron.py
|
@ -6,6 +6,7 @@ import arrow
|
|||
from arrow import Arrow
|
||||
|
||||
from app import s3
|
||||
from app.alias_utils import nb_email_log_for_mailbox
|
||||
from app.api.views.apple import verify_receipt
|
||||
from app.config import (
|
||||
IGNORED_EMAILS,
|
||||
|
@ -289,8 +290,10 @@ def sanity_check():
|
|||
sleep(1)
|
||||
if not email_domain_can_be_used_as_mailbox(mailbox.email):
|
||||
mailbox.nb_failed_checks += 1
|
||||
# alert if too much fail
|
||||
if mailbox.nb_failed_checks > 10:
|
||||
nb_email_log = nb_email_log_for_mailbox(mailbox)
|
||||
|
||||
# alert if too much fail and nb_email_log > 100
|
||||
if mailbox.nb_failed_checks > 10 and nb_email_log > 100:
|
||||
log_func = LOG.exception
|
||||
else:
|
||||
log_func = LOG.warning
|
||||
|
@ -299,7 +302,7 @@ def sanity_check():
|
|||
"issue with mailbox %s domain. #alias %s, nb email log %s",
|
||||
mailbox,
|
||||
mailbox.nb_alias(),
|
||||
mailbox.nb_email_log(),
|
||||
nb_email_log,
|
||||
)
|
||||
else: # reset nb check
|
||||
mailbox.nb_failed_checks = 0
|
||||
|
|
Loading…
Reference in New Issue