-
-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Each queue should be able to have its custom_exception or None. #215
base: master
Are you sure you want to change the base?
Changes from all commits
bfb527e
3c959b3
defa717
0c31ac3
54d4e70
c3cf7a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ class DjangoRQ(Queue): | |
def __init__(self, *args, **kwargs): | ||
autocommit = kwargs.pop('autocommit', None) | ||
self._autocommit = get_commit_mode() if autocommit is None else autocommit | ||
self.exception_handlers = kwargs.pop('exception_handlers', None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no need to store There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. About the failing tests, idk how to fix it because, once the exception handler comes in, i couldn't find how to put them in failed again if they fail. That's the problem with the test. The failed job never go to failed after a exception_handlers takes in. :( I would like some help about it , if possible. Thanks! ^^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can simply write a test for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, the test should be for |
||
|
||
super(DjangoRQ, self).__init__(*args, **kwargs) | ||
|
||
|
@@ -138,9 +139,13 @@ def get_queue(name='default', default_timeout=None, async=None, | |
default_timeout = QUEUES[name].get('DEFAULT_TIMEOUT') | ||
if queue_class is None: | ||
queue_class = get_queue_class(QUEUES[name]) | ||
|
||
exception_handlers = QUEUES[name].get('EXCEPTION_HANDLERS', None) | ||
|
||
return queue_class(name, default_timeout=default_timeout, | ||
connection=get_connection(name), async=async, | ||
autocommit=autocommit) | ||
autocommit=autocommit, | ||
exception_handlers=exception_handlers) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should also import There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fchevitarese reminder to update this PR when you're free :) |
||
|
||
|
||
def get_queue_by_index(index): | ||
|
@@ -170,9 +175,10 @@ def filter_connection_params(queue_params): | |
""" | ||
NON_CONNECTION_PARAMS = ('DEFAULT_TIMEOUT',) | ||
|
||
#return {p:v for p,v in queue_params.items() if p not in NON_CONNECTION_PARAMS} | ||
# return {p:v for p,v in queue_params.items() if p not in NON_CONNECTION_PARAMS} | ||
# Dict comprehension compatible with python 2.6 | ||
return dict((p,v) for (p,v) in queue_params.items() if p not in NON_CONNECTION_PARAMS) | ||
return dict((p, v) for (p, v) in queue_params.items() | ||
if p not in NON_CONNECTION_PARAMS) | ||
|
||
|
||
def get_queues(*queue_names, **kwargs): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
def my_custom_exception(job, exc_type, exc_value, traceback): | ||
return False |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,45 @@ | ||
from rq import Worker | ||
from rq.utils import import_attribute | ||
|
||
from .queues import get_queues | ||
from .settings import EXCEPTION_HANDLERS | ||
from .queues import get_queues | ||
|
||
|
||
def get_exception_handlers(): | ||
""" | ||
Custom exception handlers could be defined in settings.py: | ||
RQ = { | ||
'EXCEPTION_HANDLERS': ['path.to.handler'], | ||
def get_exception_handlers(queue_name): | ||
"""Custom exception handler defined in QUEUE settings: | ||
RQ_QUEUES = { | ||
'default': { | ||
'HOST': 'localhost', | ||
'PORT': 6379, | ||
'DB': 0, | ||
'PASSWORD': '', | ||
'DEFAULT_TIMEOUT': 360, | ||
'EXCEPTION_HANDLERS': [ | ||
'test_exception_handler.my_custom_exception' | ||
], | ||
} | ||
} | ||
""" | ||
return [import_attribute(path) for path in EXCEPTION_HANDLERS] | ||
|
||
if queue_name: | ||
return [import_attribute(exception_handler) for exception_handler in | ||
queue_name] | ||
else: | ||
return [import_attribute(path) for path in EXCEPTION_HANDLERS] | ||
|
||
|
||
def get_worker(*queue_names): | ||
""" | ||
Returns a RQ worker for all queues or specified ones. | ||
""" | ||
queues = get_queues(*queue_names) | ||
return Worker(queues, | ||
connection=queues[0].connection, | ||
exception_handlers=get_exception_handlers() or None) | ||
exception_handlers = get_exception_handlers(queues[0].exception_handlers) | ||
|
||
if exception_handlers: | ||
return Worker( | ||
queues, | ||
connection=queues[0].connection, | ||
exception_handlers=exception_handlers | ||
) | ||
else: | ||
return Worker(queues, connection=queues[0].connection) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is right. The function is defined as
get_exception_handlers(queue_name)
but you're passing inqueue.exception_handlers
here.