如何使用 django-celery 配置 TASK_SERIALIZER
我正在使用 django-celery,我想将 TASK_SERIALIZER 设置为 JSON 而不是 pickle。
从而在每个方法的基础上执行此操作
@task
我可以通过将我的任务装饰器从 更改为
@task(serializer="json")
但我想在全球范围内执行此操作, 。 settings.py
中的设置
TASK_SERIALIZER="json"
不起作用。尝试运行
import celery
celery.conf.TASK_SERIALIZER="json"
(如此处所暗示的那样)会导致
AttributeError: 'module' object has no attribute 'conf'
任何想法如何配置此设置当通过 django 运行 celery 时?
I'm using django-celery and I'd like to set the TASK_SERIALIZER
to JSON instead of pickle.
I can do this on a per-method basis by changing my task decorators from
@task
to
@task(serializer="json")
But I'd like to do it globally. Setting
TASK_SERIALIZER="json"
in settings.py
doesn't work. Trying to run
import celery
celery.conf.TASK_SERIALIZER="json"
(as implied here) results in
AttributeError: 'module' object has no attribute 'conf'
Any idea how to configure this setting when running celery through django?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
想通了。
在
settings.py
中,您需要设置文档令人困惑,至少对我而言。
Figured it out.
In
settings.py
you need to setDocs are confusing, at least to me.
我发现创建一个 celeryconfig 文件(如文档推荐的那样)使事情变得更加清晰。
celeryconfig.py
您可以使用此命令发送设置(一旦您调用 Celery)
I found that creating a celeryconfig file (like the docs recommend) makes things a lot cleaner.
celeryconfig.py
You can sent set it with this command (once you call Celery)
来自 文档:
因此设置
CELERY_RESULT_SERIALIZER = "json"
看起来毫无用处。就我而言,结果仍处于泡菜状态(Celery 3.1.3)。是的。我知道...From the doc :
So setting
CELERY_RESULT_SERIALIZER = "json"
looks useless. In my case, results are still in pickle (Celery 3.1.3). Yeah. I know...