Created
October 31, 2013 13:53
-
-
Save KristianOellegaard/7250161 to your computer and use it in GitHub Desktop.
Rqworker and opbeat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.management import BaseCommand | |
from rq import Worker, Queue, Connection | |
import redis | |
import logging | |
from opbeat.contrib.django.models import client | |
logger = logging.getLogger('rq.worker') | |
def register_opbeat(client, worker): | |
def send_to_opbeat(job, *exc_info): | |
client.captureException( | |
exc_info=exc_info, | |
extra={ | |
'job_id': job.id, | |
'func': job.func_name, | |
'args': job.args, | |
'kwargs': job.kwargs, | |
'description': job.description, | |
}) | |
worker.push_exc_handler(send_to_opbeat) | |
class Command(BaseCommand): | |
def handle(self, *args, **kwargs): | |
listen = ['high', 'default', 'low'] | |
conn = redis.StrictRedis(connection_pool=pool) | |
with Connection(conn): | |
worker = Worker(map(Queue, listen)) | |
register_opbeat(client, worker) | |
worker.work() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment