在网上找了半天,也没找到完整的例子,自己写吧
1. 一个队列,自定义10个优先级,修改默认celery队列名称
1) testcelery.py
from celery import Celery
import time
broker = 'redis://:passwd@127.0.0.1:6279/0'
backend = 'redis://:passwd@127.0.0.1:6279/1'
app = Celery('test',backend=backend,broker=broker)
app.conf.broker_transport_options = {
'priority_steps': list(range(10)),
'sep': ':',
'queue_order_strategy': 'priority',
}
app.conf.task_default_queue = 'autotest'
@app.task(priority=0)
def add(x, y):
time.sleep(2)
return x + y
@app.task(priority=5)
def minus(x, y):
time.sleep(1)
return x - y
@app.task(priority=8)
def multiply(x, y):
time.sleep(1)
return x * y