RQ

Scout supports RQ 1.0+.

Do the following to instrument your RQ jobs:

1. Install the scout-apm package:

pip install scout-apm

2. Use the Scout RQ worker class.

If you’re using RQ directly, you can pass the --worker-class argument the worker command:

rq worker --job-class scout_apm.rq.Worker myqueue

If you’re using the RQ Heroku pattern, you can change your code to use the scout_apm.rq.HerokuWorker class:

from scout_apm.rq import HerokuWorker as Worker

If you’re using Django-RQ, instead use the custom worker setting to point to our custom Worker class:

RQ = {
    "WORKER_CLASS": "scout_apm.rq.Worker",
}

If you’re using your own Worker sub class already, you can subclass our Worker class:

from scout_apm.rq import Worker

class MyWorker(Worker):
    # your custom behaviour here
    pass

Or if you’re combining one or more other Worker classes, you can add our mixin class scout_apm.rq.WorkerMixin:

from some.other.rq.extension import CustomWorker
from scout_apm.rq import WorkerMixin

class MyWorker(WorkerMixin, CustomWorker):
    pass

3. Configure Scout.

If you’re using Django-RQ, ensure you have the Django integration installed, and this is handled for you.

If you’re using RQ directly, create a config file for it that runs the Scout API’s Config.set():

from scout_apm.api import Config
  
Config.set(
    key="YOUR_SCOUT_KEY",
    name="Same as Web App Name",
    monitor=True,
)

Pass the config file to -c argument to the worker command, as per the documentation.

If you wish to configure Scout via environment variables, you don’t need a config file. Set SCOUT_KEY, SCOUT_NAME and SCOUT_MONITOR instead.

If you’ve installed Scout via the Heroku Addon, the provisioning process automatically sets SCOUT_MONITOR and SCOUT_KEY via config vars. Only SCOUT_NAME is required.

4. Deploy.

It takes approximatively five minutes for your data to first appear within the Scout UI.

Tasks will appear in the “Background Jobs” area of the Scout UI.