Celery、flower和celery-redis 的安装与使用

0x01 安装celery

pip install Celery

0x02 安装celery-redis
celery-redis:如果把redis当做broker,需要安装

pip install -U celery-with-redis
pip install MySQL-python
0x03 安装flower

pip install flower
0x04 启动flower

/usr/local/bin/python2.7 /usr/local/bin/flower --port=7788 --broker=redis://localhost:6379/0 --broker_api=redis://localhost:6379/0
0x05 使用celery

[root@MyServer ~]# cat tasks.py
import time
from celery import Celery, platforms 
platforms.C_FORCE_ROOT = True
celery = Celery('tasks', broker='redis://localhost:6379/0')
 
@celery.task
def add(x,y):
    return x+y

接着启动celery:
celery -A tasks worker --loglevel=info

然后新建个shell,在python下,输入:
>>> from tasks import *
>>> add.delay(1,2)
<AsyncResult: 1a0a9262-7858-4192-9981-b7bf0ea7483b>
可以在worker里看到:
[2013-08-27 19:20:23,363: WARNING/MainProcess] celery@MichaeliMac.local ready.
[2013-08-27 19:20:23,367: INFO/MainProcess] consumer: Connected to redis://localhost:6379/0.
[2013-08-27 19:20:45,618: INFO/MainProcess] Got task from broker: tasks.sendmail[1a0a9262-7858-4192-9981-b7bf0ea7483b]
[2013-08-27 19:20:45,655: WARNING/PoolWorker-4] sending mail to celery@python.org...
[2013-08-27 19:20:47,657: WARNING/PoolWorker-4] mail sent.
[2013-08-27 19:20:47,658: INFO/MainProcess] Task tasks.sendmail[1a0a9262-7858-4192-9981-b7bf0ea7483b] succeeded in 2.00266814232s: 3


tips:http://blog.csdn.net/jazywoo123/article/details/17636615
————————————————

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值