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()
|
cls.query.filter(cls.id == obj_id).delete()
|
||||||
db.session.commit()
|
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
|
@property
|
||||||
def aliases(self) -> [Alias]:
|
def aliases(self) -> [Alias]:
|
||||||
ret = Alias.filter_by(mailbox_id=self.id).all()
|
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 arrow import Arrow
|
||||||
|
|
||||||
from app import s3
|
from app import s3
|
||||||
|
from app.alias_utils import nb_email_log_for_mailbox
|
||||||
from app.api.views.apple import verify_receipt
|
from app.api.views.apple import verify_receipt
|
||||||
from app.config import (
|
from app.config import (
|
||||||
IGNORED_EMAILS,
|
IGNORED_EMAILS,
|
||||||
|
@ -289,8 +290,10 @@ def sanity_check():
|
||||||
sleep(1)
|
sleep(1)
|
||||||
if not email_domain_can_be_used_as_mailbox(mailbox.email):
|
if not email_domain_can_be_used_as_mailbox(mailbox.email):
|
||||||
mailbox.nb_failed_checks += 1
|
mailbox.nb_failed_checks += 1
|
||||||
# alert if too much fail
|
nb_email_log = nb_email_log_for_mailbox(mailbox)
|
||||||
if mailbox.nb_failed_checks > 10:
|
|
||||||
|
# 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
|
log_func = LOG.exception
|
||||||
else:
|
else:
|
||||||
log_func = LOG.warning
|
log_func = LOG.warning
|
||||||
|
@ -299,7 +302,7 @@ def sanity_check():
|
||||||
"issue with mailbox %s domain. #alias %s, nb email log %s",
|
"issue with mailbox %s domain. #alias %s, nb email log %s",
|
||||||
mailbox,
|
mailbox,
|
||||||
mailbox.nb_alias(),
|
mailbox.nb_alias(),
|
||||||
mailbox.nb_email_log(),
|
nb_email_log,
|
||||||
)
|
)
|
||||||
else: # reset nb check
|
else: # reset nb check
|
||||||
mailbox.nb_failed_checks = 0
|
mailbox.nb_failed_checks = 0
|
||||||
|
|
Loading…
Reference in New Issue