django-celery-transactions icon indicating copy to clipboard operation
django-celery-transactions copied to clipboard

Catching exceptions when Celery broker is down

Open antonpirker opened this issue 9 years ago • 1 comments

Hello!

First: thank's for this package, it is really useful in our project! I have one problem: In one of my views a signal is triggered which then calls a celery task like this:

def post_save_donation(sender, instance, created, raw, using, **kwargs):
    create_something.delay(pk)

post_save.connect(post_save_donation, sender=Donation)

The task is defined like this:

from djcelery_transactions import task

@task
def create_something(donation_pk):
    # do something

Everything works great, but:

If RabbitMQ is down when I am calling the task no error is thrown during the create_something.delay(pk) call. But the view throws this error:

[Errno 111] Connection refused

The question now is: Why is this error thrown in the view but not in the signal handler where the create_something.delay(pk) is called?

Any help is greatly appreciated

antonpirker avatar Sep 23 '15 17:09 antonpirker

I think you're simply not trying to catch the error in the signal, so it's bubbling up to the highest level, and the Django view will catch it if you don't.

Make sure to add a try...except in your signal.

Let me know if I misunderstand the issue

nicolasgrasset avatar Oct 07 '15 03:10 nicolasgrasset