To get rq workers talking to opbeat at this current time, you must use a custom rq exception handler and add it to the chain that the worker accepts. This allows us to call opbeat synchronously and avoid the current issues with the opbeat library's async workers.
Both of the examples below keep the original rq exception handler functionality of moving a failed job to the failed queue, but this is optional - if you only want opbeat logging then just don't pass the move_to_failed_queue
handler.
Note that we send a lot of extra information about the job itself (see _get_job_details
) but this is not a requirement, the stack you get is useful enough without it.
If using django-rq, you'll want your to insert the custom handler by using the RQ_EXCEPTION_HANDLERS setting in your normal Django settings file. e.g
RQ_EXCEPTION_HANDLERS = (
'python.module.path.to.log_to_opbeat', # Module string to above handler.
'rq.handlers.move_to_failed_queue', # Module string to default rq handler.
)
If using rq directly, you'll want to pass the exception handler functions
directly in to the Worker __init__
. More like this:
from rq.worker import Worker
from rq.handlers import move_to_failed_queue
from my_program.rq_handlers import log_to_opbeat
w = Worker(queues, exception_handlers=[log_to_opbeat, move_to_failed_queue])