Explorar el Código

Using the loader for mail_admins so it can be overridden in the Django Loader

sdcooke hace 14 años
padre
commit
904780e3e3
Se han modificado 2 ficheros con 16 adiciones y 12 borrados
  1. 7 12
      celery/app/base.py
  2. 9 0
      celery/loaders/base.py

+ 7 - 12
celery/app/base.py

@@ -272,22 +272,17 @@ class BaseApp(object):
                     seconds=c.CELERY_TASK_RESULT_EXPIRES)
         return c
 
-    def mail_admins(self, subject, message, fail_silently=False):
+    def mail_admins(self, subject, body, fail_silently=False):
         """Send an e-mail to the admins in conf.ADMINS."""
-        from celery.utils import mail
-
         if not self.conf.ADMINS:
             return
-
         to = [admin_email for _, admin_email in self.conf.ADMINS]
-        message = mail.Message(sender=self.conf.SERVER_EMAIL,
-                               to=to, subject=subject, body=message)
-
-        mailer = mail.Mailer(self.conf.EMAIL_HOST,
-                             self.conf.EMAIL_PORT,
-                             self.conf.EMAIL_HOST_USER,
-                             self.conf.EMAIL_HOST_PASSWORD)
-        mailer.send(message, fail_silently=fail_silently)
+        self.loader.mail_admins(subject, body, fail_silently,
+                                to=to, sender=self.conf.SERVER_EMAIL,
+                                host=self.conf.EMAIL_HOST,
+                                port=self.conf.EMAIL_PORT,
+                                user=self.conf.EMAIL_USER,
+                                password=self.conf.EMAIL_PASSWORD)
 
     def AsyncResult(self, task_id, backend=None):
         """Create :class:`celery.result.BaseAsyncResult` instance."""

+ 9 - 0
celery/loaders/base.py

@@ -112,6 +112,15 @@ class BaseLoader(object):
 
         return dict(map(getarg, args))
 
+    def mail_admins(self, subject, message, fail_silently=False,
+            sender=None, to=None, host=None, port=None, 
+            user=None, password=None):
+        from celery.utils import mail
+        message = mail.Message(sender=sender,
+                               to=to, subject=subject, body=message)
+        mailer = mail.Mailer(host, port, user, password)
+        mailer.send(message, fail_silently=fail_silently)
+
     @property
     def conf(self):
         """Loader configuration."""