Celery 使用
celery.py
from celery import Celery
from celery.schedules import crontab
broker = 'redis://127.0.0.1:6379/1' # broker任务队列
backend = 'redis://127.0.0.1:6379/2' # 结构存储,执行完的结果存在这
app = Celery(__name__, broker=broker, backend=backend, include=['celery_task.task1',])
app.conf.CELERY_TIMEZONE = 'Asia/Shanghai'
# 是否使用UTC
app.conf.CELERY_ENABLE_UTC = False
# 任务的定时配置
from datetime import timedelta
app.conf.CELERYBEAT_SCHEDULE = {
'add-task': {
'task': 'celery_task.task1.add',
'schedule': timedelta(minutes=1), # crontab(minute='*/1') timedelta(seconds=60)
}
}
task1.py
import json
import requests
from .celery import app
from kgw.utils.get_pool import get_pool2
from kgw.utils.get_goods import Get_goods
@app.task
def add():
业务