Permalink
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...
1 parent 4d7069c commit b664582f911340cfdfd492c6fd3f509225b2c0c7 @brosner brosner committed Dec 10, 2008
Showing with 14 additions and 0 deletions.
  1. +14 −0 notification/engine.py
View
@@ -1,14 +1,18 @@
+import sys
import time
import logging
+import traceback
try:
import cPickle as pickle
except ImportError:
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()

0 comments on commit b664582

Please sign in to comment.