Django如何使用6.4版本的Celery?
- 内容介绍
- 文章标签
- 相关推荐
本文共计313个文字,预计阅读时间需要2分钟。
Celery官方网站中,中文文档示例一:用户发起request,并等待response返回。在本地的views中,可能需要执行一段耗时的程序,那么用户就会等待很长时间,造成不良的用户体验。
celery
- 官方网站
- 中文文档
- 示例一:用户发起request,并等待response返回。在本些views中,可能需要执行一段耗时的程序,那么用户就会等待很长时间,造成不好的用户体验
- 示例二:网站每小时需要同步一次天气预报信息,但是127.0.0.1:6379/0'
CELERY_IMPORTS = ('应用名称.task')- 在应用目录下创建task.py文件
from celery import task
@task
def sayhello():
print('hello ...')
time.sleep(2)
print('world ...')- 迁移,生成celery需要的数据表
- 启动Redis
- 启动worker
- 调用语法
- 使用代码
def sayhello(request):
print('hello ...')
import time
time.sleep(10)
print('world ...')
# sayhello.delay()
return HttpResponse("hello world")
本文共计313个文字,预计阅读时间需要2分钟。
Celery官方网站中,中文文档示例一:用户发起request,并等待response返回。在本地的views中,可能需要执行一段耗时的程序,那么用户就会等待很长时间,造成不良的用户体验。
celery
- 官方网站
- 中文文档
- 示例一:用户发起request,并等待response返回。在本些views中,可能需要执行一段耗时的程序,那么用户就会等待很长时间,造成不好的用户体验
- 示例二:网站每小时需要同步一次天气预报信息,但是127.0.0.1:6379/0'
CELERY_IMPORTS = ('应用名称.task')- 在应用目录下创建task.py文件
from celery import task
@task
def sayhello():
print('hello ...')
time.sleep(2)
print('world ...')- 迁移,生成celery需要的数据表
- 启动Redis
- 启动worker
- 调用语法
- 使用代码
def sayhello(request):
print('hello ...')
import time
time.sleep(10)
print('world ...')
# sayhello.delay()
return HttpResponse("hello world")

