Преглед изворни кода

sanity_check: alert when too many checks fail on a mailbox

Son NK пре 5 година
родитељ
комит
28da78e75f
1 измењених фајлова са 12 додато и 1 уклоњено
  1. 12 1
      cron.py

+ 12 - 1
cron.py

@@ -279,12 +279,23 @@ def sanity_check():
         # hack to not query DNS too often
         sleep(1)
         if not email_domain_can_be_used_as_mailbox(mailbox.email):
-            LOG.error(
+            mailbox.nb_failed_checks += 1
+            # alert if too much fail
+            if mailbox.nb_failed_checks > 10:
+                log_func = LOG.error
+            else:
+                log_func = LOG.warning
+
+            log_func(
                 "issue with mailbox %s domain. #alias %s, nb email log %s",
                 mailbox,
                 mailbox.nb_alias(),
                 mailbox.nb_email_log(),
             )
+        else:  # reset nb check
+            mailbox.nb_failed_checks = 0
+
+    db.session.commit()
 
     for user in User.filter_by(activated=True).all():
         if user.email.lower() != user.email: