开发者

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?


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜