Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

fchevitarese
Copy link

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
Author

How can i run tests in my machine?

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

selwin commented Feb 3, 2017

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
Author

Will do ;)

@fchevitarese
Copy link
Author

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

Take a look and see if it fits ^^

}
"""
return [import_attribute(path) for path in EXCEPTION_HANDLERS]
try:
from django.settings import RQ_EXCEPTION_HANDLERS
Copy link
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
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
Author

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

Cheers!

Custom exception handlers could be defined in settings.py:
RQ = {
'EXCEPTION_HANDLERS': ['path.to.handler'],
def get_exception_handlers(exception_handlers):
Copy link
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)

@@ -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)
Copy link
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
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
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
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
Copy link
Collaborator

selwin commented Mar 15, 2017

@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
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!

@@ -77,7 +77,8 @@ def handle(self, *args, **options):
queues,
connection=queues[0].connection,
name=options['name'],
exception_handlers=get_exception_handlers() or None,
exception_handlers=get_exception_handlers(
Copy link
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.

return queue_class(name, default_timeout=default_timeout,
connection=get_connection(name), async=async,
autocommit=autocommit)
autocommit=autocommit,
exception_handlers=exception_handlers)
Copy link
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
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
Copy link
Author

fchevitarese commented Jul 23, 2017 via email

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