Skip to content

Commit cdd4d8c

Browse files
committed
Merge pull request #160 from sbussetti/master
Clean up EXCEPTION_HANDLER implementation
2 parents a99abf7 + 4fad083 commit cdd4d8c

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ Installation
5050
'high': {
5151
'URL': os.getenv('REDISTOGO_URL', 'redis://localhost:6379/0'), # If you're on Heroku
5252
'DEFAULT_TIMEOUT': 500,
53-
'EXCEPTION_HANDLERS': ['path.to.my.handler'], # If you need custom exception handlers
5453
},
5554
'low': {
5655
'HOST': 'localhost',
@@ -59,6 +58,8 @@ Installation
5958
}
6059
}
6160
61+
RQ_EXCEPTION_HANDLERS = ['path.to.my.handler'] # If you need custom exception handlers
62+
6263
* Include ``django_rq.urls`` in your ``urls.py``:
6364

6465
.. code-block:: python

django_rq/management/commands/rqscheduler.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,16 @@ class Command(BaseCommand):
2020
help="How often the scheduler checks for new jobs to add to the "
2121
"queue (in seconds).",
2222
),
23+
make_option(
24+
'--queue',
25+
type=str,
26+
dest='queue',
27+
default='default',
28+
help="Name of the queue used for scheduling.",
29+
),
2330
)
2431

25-
def handle(self, queue='default', *args, **options):
26-
scheduler = get_scheduler(name=queue, interval=options.get('interval'))
32+
def handle(self, *args, **options):
33+
scheduler = get_scheduler(
34+
name=options.get('queue'), interval=options.get('interval'))
2735
scheduler.run()

django_rq/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919
QUEUES_LIST.append({'name': key, 'connection_config': value})
2020
for config in get_unique_connection_configs():
2121
QUEUES_LIST.append({'name': 'failed', 'connection_config': config})
22+
23+
# Get exception handlers
24+
EXCEPTION_HANDLERS = getattr(settings, 'RQ_EXCEPTION_HANDLERS', [])

django_rq/workers.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from django.conf import settings
2-
31
from rq import Worker
42
from rq.utils import import_attribute
53

64
from .queues import get_queues
5+
from .settings import EXCEPTION_HANDLERS
76

87

98
def get_exception_handlers():
@@ -13,12 +12,7 @@ def get_exception_handlers():
1312
'EXCEPTION_HANDLERS': ['path.to.handler'],
1413
}
1514
"""
16-
RQ = getattr(settings, 'RQ', {})
17-
exception_handlers = []
18-
for path in RQ.get('EXCEPTION_HANDLERS', []):
19-
handler = import_attribute(path)
20-
exception_handlers.append(handler)
21-
return exception_handlers
15+
return [import_attribute(path) for path in EXCEPTION_HANDLERS]
2216

2317

2418
def get_worker(*queue_names):

0 commit comments

Comments
 (0)