Skip to content

Commit

Permalink
add --worker-class option
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbrooks committed Feb 12, 2014
1 parent 7312474 commit 0d43dcd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.rst
Expand Up @@ -143,6 +143,11 @@ If you want to run ``rqworker`` in burst mode, you can pass in the ``--burst`` f

python manage.py rqworker high default low --burst

If you need to use a custom worker class, you can pass in the ``--worker-class`` flag
with the path to your worker::
python manage.py rqworker high default low --worker-class 'path.to.GeventWorker'
Support for RQ Scheduler
------------------------

Expand Down
17 changes: 14 additions & 3 deletions django_rq/management/commands/rqworker.py
Expand Up @@ -6,10 +6,10 @@

from redis.exceptions import ConnectionError

from django_rq.workers import get_worker
from django_rq.queues import get_queues

from rq import use_connection

from rq.utils import import_attribute

# Setup logging for RQWorker if not already configured
logger = logging.getLogger('rq.worker')
Expand Down Expand Up @@ -58,12 +58,23 @@ class Command(BaseCommand):
default=False,
help='Run worker in burst mode'
),
make_option(
'--worker-class',
action='store',
dest='worker_class',
default='rq.Worker',
help='RQ Worker class to use'
),
)
args = '<queue queue ...>'

def handle(self, *args, **options):
try:
w = get_worker(*args)
# Instantiate a worker
worker_class = import_attribute(options.get('worker_class', 'rq.Worker'))
queues = get_queues(*args)
w = worker_class(queues, connection=queues[0].connection)

# Call use_connection to push the redis connection into LocalStack
# without this, jobs using RQ's get_current_job() will fail
use_connection(w.connection)
Expand Down

0 comments on commit 0d43dcd

Please sign in to comment.