Permalink
Browse files

Catch all errors in worker process and log it, don't crash

  • Loading branch information...
1 parent 6aacd81 commit 4defbecd1e9c39c89ad25dc3a12988c24c99e27d @jonasvp committed Jul 9, 2010
Showing with 15 additions and 3 deletions.
  1. +15 −3 django_beanstalkd/management/commands/beanstalk_worker.py
@@ -1,3 +1,4 @@
+import logging
from optparse import make_option
import os
import sys
@@ -104,9 +105,20 @@ def work(self):
job = beanstalk.reserve()
job_name = job.stats()['tube']
if job_name in self.jobs:
- #print "Calling %s with arg: %s" % (job_name, job.body)
- self.jobs[job_name](job.body)
- job.delete()
+ logging.debug("Calling %s with arg: %s" % (job_name, job.body))
+ try:
+ self.jobs[job_name](job.body)
+ except Exception, e:
+ logging.error('Error while calling "%s" with arg "%s": '
+ '%s' % (
+ job_name,
+ job.body,
+ e,
+ )
+ )
+ job.bury()
+ else:
+ job.delete()
else:
job.release()

0 comments on commit 4defbec

Please sign in to comment.