Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Signals in celery

I have a task that runs in a Celerybeat instance. When that task is executed, it sometimes modifies a model object, which should fire off a post/pre_save signal, but it doesn't. The signal is not happening. I imagine this is due to Django's signals being synchronous while celery is doing it's thing on a different server in a different thread in a different universe. Is there a simple way to still get those signals to fire while they're being ran in celery?

like image 262
priestc Avatar asked Oct 13 '10 01:10

priestc


1 Answers

Django signals are local, which means that the signal handler must be registered in the worker as well.

If your signal handler is connected in e.g. models.py, then you need to import that in tasks.py to make sure it's also connected in the worker.

Alternatively you can specify additional modules the worker should import using the CELERY_IMPORTS setting:

CELERY_IMPORTS = ("myapp.handlers", )

or the -I argument to celeryd.

$ python manage.py celeryd -I myapp.handlers
like image 53
asksol Avatar answered Oct 01 '22 03:10

asksol