celery

celery

  1. 启动rabbit

  2. rabbitmq-server

  3. 文件 test.py

from celery import Celery

app = Celery('tasks', broker='amqp://[email protected]//')

@app.task
def add(x, y):
    return x + y    
  1. 启动celery任务:celery -A test worker –loglevel=info

注意:其中的test 是文件的名字

  1. 配置backend 参照官网

  2. 可以单独写配置文件 config.py

CELERY_RESULT_BACKEND = "database"
CELERY_RESULT_DBURL = "sqlite:///temp.db"
  1. 在test.py文件中引入
from celery import Celery
app = Celery()
app.config_from_object('config')
@app.task
def.....