目录结构
配置
点击查看代码
from celery import Celery,platforms
from kombu import Exchange, Queue
platforms.C_FORCE_ROOT = True
broker = 'redis://127.0.0.1:6380/1'
backend = 'redis://127.0.0.1:6380/2'
app = Celery(
'sxj',
broker=broker,
backend=backend,
include=[
'sxj.task',
'task1',
'task2',
'task3.task'
]
)
'''
设置队列
'''
set_queue = (
Queue('default',Exchange('default',type='direct'),routing_key='default'),
Queue('Q1',Exchange('Q1',type='direct'),routing_key='Q1'),
)
'''
配置
'''
app.conf.update(
CELERY_TASK_SERIALIZER = 'json',
CELERY_ACCEPT_CONTENT = ['json'],
CELERY_RESULT_SERIALIZER = 'json',
CELERY_TIMEZONE = 'Asia/Shanghai',
CELERY_ENABLE_UTC = True,
CELERYD_CONCURRENCY = 2, #并发worker数
CELERYD_MAX_TASKS_PER_CHILD = 5,
CELERYD_PREFETCH_MULTIPLIER = 2, # worker每次去redis取任务的数量
CELERYD_TASK_TIME_LIMIT = 3600, # 超时
CELERY_QUEUES=set_queue,
CELERY_DEFAULT_QUEUE = 'default',
CELERY_DEFAULT_EXCHANGE = 'default',
CELERY_DEFAULT_ROUTING_KEY = 'default',
)