标签:redis dock ade -- ati efault 使用 evel celery
https://segmentfault.com/a/1190000015654877
http://yshblog.com/blog/163
dj2.x py3
docker run --name myredis -v /etc/localtime:/etc/locatime -v /data:/data -p 6379:6379 -d redis redis-server --appendonly yes
pip3 install celery==3.1.25
pip3 install celery-with-redis==3.0
pip3 install django-celery==3.2.1
- 激活app
djcelery
- settings.py
#celery
import djcelery
djcelery.setup_loader()
#配置redis数据库
#redis://:密码@ip:端口/库
BROKER_URL='redis://:sunck@127.0.0.1:6379/0'
#配置任务文件
CELERY_IMPORTS=("myApp.task")
- 项目下celery.py
import os
from celery import Celery
from django.conf import settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'whthas_home.settings')
app = Celery('portal')
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
- 项目下导入
项目中的__init__.py文件中添加from .celery import app as celery_app
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
- views.py
from myApp.task import longIO
def registe(request):
longIO.delay()
return HttpResponse("sunck is a good man")
- 启动redis(我用的docker)
- 启动worker
python manage.py celery worker --loglevel=info
- 启动django
标签:redis dock ade -- ati efault 使用 evel celery
原文地址:https://www.cnblogs.com/iiiiiher/p/9354014.html