priestc
priestc

Reputation: 35180

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?

Upvotes: 11

Views: 4602

Answers (1)

asksol
asksol

Reputation: 19499

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

Upvotes: 21

Related Questions