Skip to content

Instantly share code, notes, and snippets.

@KristianOellegaard
Created October 31, 2013 13:53
Show Gist options
  • Save KristianOellegaard/7250161 to your computer and use it in GitHub Desktop.
Save KristianOellegaard/7250161 to your computer and use it in GitHub Desktop.
Rqworker and opbeat
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