celery介绍 - 18965050/python-celery GitHub Wiki

任务队列

任务队列是一种工作在跨线程或机器中的机制. Task queues are used as a mechanism to distribute work across threads or machines.

任务队列中的输入是一种被称为任务的工作单元. celery通过消息和broker代理来进行沟通. 要发起一个任务, client将消息放入任务队列, 由broker发送到worker中去执行.

celery能协同多个worker和broker工作, 具有非常高的可用性和横向扩展性.

celery是使用python编写的, 但协议实现可使用任何语言. 比如RCelery针对Ruby语言使用, node-celery针对Node.js和PHP client. 不同语言的交互还可以通过webhook方式来实现.

使用celery要求能传输和接收消息. RabbitMQ和Redis代理是所有特性都支持的, 但还有很多其他可用于实验阶段的broker,包括针对本地开发的SQLite

celery可运行在单机器, 多机器或数据中心上.

Application

celery的配置可通过

app.conf.CELERY_XXX=YYY

这种方式, 也可以通过

app.config_from_object()

来配置. 比如:

# 方式一
from celery import Celery

app = Celery()
import celeryconfig
app.config_from_object(celeryconfig)

#方式二
from celery import Celery

app = Celery()

class Config:
    CELERY_ENABLE_UTC = True
    CELERY_TIMEZONE = 'Europe/London'

app.config_from_object(Config)

, 或通过config_from_envvar来配置

import os
from celery import Celery

#: Set default configuration module name
os.environ.setdefault('CELERY_CONFIG_MODULE', 'celeryconfig')

app = Celery()
app.config_from_envvar('CELERY_CONFIG_MODULE')