美文网首页
Using Celery with Django

Using Celery with Django

作者: 你猜_19ca | 来源:发表于2019-02-15 16:29 被阅读0次

安装

pip install celery
pip install sqlalchemy

  • 可选安装
  1. 如果broker使用redis,则pip install -U "celery[redis]"

    此处有坑: celery4.0以上的broker只能用redis==2.10.6版本的,否则会报"AttributeError"

  2. 如果celery安装在windows上,需要额外安装eventlet. pip install eventlet

    此处又是坑: win10上运行celery4.x会报如下错误:
    ValueError: not enough values to unpack (expected 3, got 0)

    启动celery需要带上参数: celery -A <mymodule> worker -l info -P eventlet

  3. 安装flower, 可视化celery监控软件
    pip install flower
    启动flower: celery flower worker -A <mymodule>

配置Django

  • settings配置
from __future__ import absolute_import, unicode_literals
...
# Celery settings

CELERY_BROKER_URL = 'amqp://guest:guest@localhost//'
# CELERY_BROKER_URL = 'redis://localhost:6379/0'

#: Only add pickle to this list if your broker is secured
#: from unwanted access (see userguide/security.html)
CELERY_ACCEPT_CONTENT = ['json']
CELERY_RESULT_BACKEND = 'db+sqlite:///results.sqlite'
CELERY_TASK_SERIALIZER = 'json'

其他参考: http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html#using-celery-with-django

相关文章

网友评论

      本文标题:Using Celery with Django

      本文链接:https://www.haomeiwen.com/subject/vfkmeqtx.html