Skip to content

Instantly share code, notes, and snippets.

@skyler
Created August 30, 2012 00:40
Show Gist options
  • Save skyler/3521065 to your computer and use it in GitHub Desktop.
Save skyler/3521065 to your computer and use it in GitHub Desktop.
from gearman import GearmanWorker
from traceback import format_exception, print_exception
from StringIO import StringIO
import logging
class ExceptionalGearmanWorker(GearmanWorker):
def on_job_exception(self, current_job, exception_tuple):
""" Override the default on_job_exception handler to log an error
to the console.
"""
sbuffer = StringIO()
print_exception(exception_tuple[0], exception_tuple[1],
exception_tuple[2], file=sbuffer)
logging.error(sbuffer.getvalue())
return super(ExceptionalGearmanWorker, self).on_job_exception(current_job, exception_tuple)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment