Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Catch exceptions while processing the queue and handle them nicely an…

…d e-mail them to ADMINS.

git-svn-id: http://django-notification.googlecode.com/svn/trunk@119 590c3fc9-4838-0410-bb95-17a0c9b37ca9
  • Loading branch information...
commit b664582f911340cfdfd492c6fd3f509225b2c0c7 1 parent 4d7069c
@brosner brosner authored
Showing with 14 additions and 0 deletions.
  1. +14 −0 notification/engine.py
View
14 notification/engine.py
@@ -1,6 +1,8 @@
+import sys
import time
import logging
+import traceback
try:
import cPickle as pickle
@@ -8,7 +10,9 @@
import pickle
from django.conf import settings
+from django.core.mail import mail_admins
from django.contrib.auth.models import User
+from django.contrib.sites.models import Site
from lockfile import FileLock, AlreadyLocked, LockTimeout
@@ -48,6 +52,16 @@ def send_all():
sent += 1
queued_batch.delete()
batches += 1
+ except:
+ # get the exception
+ exc_class, e, t = sys.exc_info()
+ # email people
+ current_site = Site.objects.get_current()
+ subject = "[%s emit_notices] %r" % (current_site.name, e)
+ message = "%s" % ("\n".join(traceback.format_exception(*sys.exc_info())),)
+ mail_admins(subject, message, fail_silently=True)
+ # log it as critical
+ logging.critical("an exception occurred: %r" % e)
finally:
logging.debug("releasing lock...")
lock.release()
Please sign in to comment.
Something went wrong with that request. Please try again.