celery 如何快速做定时任务
流程图快速复习
1.delay_task.py文件
# 定时任务 用shared_task装饰的就是定时任务
from celery import shared_task
import asyncio
# 异步任务
async def consume():
# 你的代码逻辑
return 'test'
#用shared_task装饰的就是定时任务
@shared_task
def async_consume():
return asyncio.run(consume())
2. my_task.py文件
# 导入异步任务队列库
from celery import Celery
import asyncio
# 建立实例
app = Celery('tornado')
# 设置代理/队列 redis 消息队列 rabbitmq rocketmq kafka
app.conf.broker_url = 'redis://localhost:6379'
# 设置任务结果
app.conf.result_backend = 'redis://localhost:6379'
# 设置时区
app.conf.timezone = 'Asia/Shanghai'
# 导入定时任务列表
app.conf['imports'] = ['delay