Skip to content

Each queue should be able to have its custom_exception or None. - #215

Open
fchevitarese wants to merge 6 commits into
rq:masterfrom
fchevitarese:CUSTOM_EXCEPTION_PER_QUEUE
Open

Each queue should be able to have its custom_exception or None.#215
fchevitarese wants to merge 6 commits into
rq:masterfrom
fchevitarese:CUSTOM_EXCEPTION_PER_QUEUE

Conversation

@fchevitarese

Copy link
Copy Markdown

Each queue should be able to have its custom_exception or None.

Make a global custom_exception may lead us to a non desired behavior on other queues.

@fchevitarese

Copy link
Copy Markdown
Author

How can i run tests in my machine?

… of a test. I cannot send a failed job to failed
@selwin

selwin commented Feb 3, 2017

Copy link
Copy Markdown
Collaborator

I agree that this is a good idea. However, I'd like to keep it backwards compatible if we can. Could you please change your PR to make exception_handlers fallback to RQ_EXCEPTION_HANDLERS?

@fchevitarese

Copy link
Copy Markdown
Author

Will do ;)

@fchevitarese

Copy link
Copy Markdown
Author

i'm sorry, i was really busy those days ;)

Take a look and see if it fits ^^

Comment thread django_rq/workers.py Outdated
"""
return [import_attribute(path) for path in EXCEPTION_HANDLERS]
try:
from django.settings import RQ_EXCEPTION_HANDLERS

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RQ_EXCEPTION_HANDLERS should only be a fallback. So we only try to import it if exception_handlers is None.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, i will rewrite asap ;)

@fchevitarese

Copy link
Copy Markdown
Author

Done, could you take a look if it's ok?

Cheers!

Comment thread django_rq/workers.py Outdated
Custom exception handlers could be defined in settings.py:
RQ = {
'EXCEPTION_HANDLERS': ['path.to.handler'],
def get_exception_handlers(exception_handlers):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to change the function signature to get_exception_handlers(queue_name)

Comment thread django_rq/queues.py
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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to store exception_handlers as property in DjangoRQ

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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! ^^

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simply write a test for get_queue('default') and ensure that queue.exception_handlers contains the exception handler you specified in settings.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, the test should be for get_worker() because only workers have exception_handlers. Queue objects have no exception_handlers in RQ.

@selwin

selwin commented Mar 15, 2017

Copy link
Copy Markdown
Collaborator

@fchevitarese could you also fix the failing tests?

…s by checking if have a custom exception, otherwise, it start a Worker without the parameter.
@fchevitarese

Copy link
Copy Markdown
Author

@selwin , the only way i found to fix the testing was to check if exception_handler exists, and if not, start a Worker without the parameter.
Even when there's no [exception_handler] it was raising the error when trying to get the failing job to requeue.

I'm not sure why, and i couldn't find a way to fix this problem in other way.

About the property "self.exception_handlers = kwargs.pop('exception_handlers', None)" i removed, but started to face a lot of errors, so i put it back.

Hope it's all good!

connection=queues[0].connection,
name=options['name'],
exception_handlers=get_exception_handlers() or None,
exception_handlers=get_exception_handlers(

Copy link
Copy Markdown
Collaborator

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 in queue.exception_handlers here.

Comment thread django_rq/queues.py
connection=get_connection(name), async=async,
autocommit=autocommit)
autocommit=autocommit,
exception_handlers=exception_handlers)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also import exception_handlers before passing it into __init__

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fchevitarese reminder to update this PR when you're free :)

@fchevitarese

fchevitarese commented Jul 23, 2017 via email

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants