Skip to content

Commit

Permalink
Catch exceptions while processing the queue and handle them nicely an…
Browse files Browse the repository at this point in the history
…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
brosner committed Dec 10, 2008
1 parent 4d7069c commit b664582
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions notification/engine.py
@@ -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

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit b664582

Please sign in to comment.