python celery + redis

redis
http://debugo.com/python-redis

celery
https://gist.github.com/neara/11214948
https://gist.github.com/amatellanes/a986f6babb9cf8556e36
https://gist.github.com/IrSent/5e4820f6b187d3654967b55e27d5d204

http://funhacks.net/2016/12/13/celery/
https://www.ibm.com/developerworks/cn/opensource/os-cn-celery-web-service/index.html

http://docs.jinkan.org/docs/celery/getting-started/introduction.html
http://liuzxc.github.io/blog/celery/
https://realpython.com/blog/python/flask-by-example-implementing-a-redis-task-queue
http://liuzxc.github.io/blog/celery
http://blog.wifibao.im/index.php/archives/166
http://www.jianshu.com/p/1840035cb510
http://www.jianshu.com/p/9e422d9f1ce2

flask & celery:
https://blog.miguelgrinberg.com/post/using-celery-with-flask
http://liyangliang.me/posts/2015/11/using-celery-with-flask
http://shulhi.com/celery-integration-with-flask
http://aviaryan.in/blog/gsoc/celery-flask-using.html
http://doc.scalingo.com/languages/python/celery/getting-started-with-celery-and-flask
http://www.adikrishnan.in/2016/03/03/using-celery-with-flask/

flask & celery & redis:
http://celeodor.com/flask-flask-socketio-celery-and-redis-background-task-processing
https://moinulhossain.me/remote-celery-worker-for-flask-with-separate-code-base

http://louistiao.me/posts/deploy-flask-with-a-celery-task-queue-and-flower-dashboard-using-kubernetes
http://www.cnblogs.com/ajianbeyourself/p/4471391.html

ansible & celery
http://fengxsong.github.io/2016/05/27/ansible-celery

https://github.com/Erazx/ansible_api
https://github.com/onlytiancai/ansible-celery-flask-demo
https://github.com/yumaojun03/ansible_async_api
https://github.com/fengxsong/django-example

http://www.cnblogs.com/piperck/p/5391128.html

http://www.revsys.com/12days

564063-20161121105103706-54381362.jpg

yum -y install redis
chkconfig redis on && /etc/init.d/redis start

venv

pip install redis -i https://pypi.douban.com/simple
pip install celery -i https://pypi.douban.com/simple
broker(broker.py)
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import

from celery import Celery, platforms
platforms.C_FORCE_ROOT = True

app = Celery(__name__, broker='redis://127.0.0.1:6379/0', backend='redis://127.0.0.1:6379/0', include=['tasks'])
worker(tasks.py)
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from broker import app
import time

@app.task
def longtime_add(x, y):
    print 'long time task begins'
    # sleep 5 seconds
    time.sleep(5)
    print 'long time task finished'
    return x + y
client(run_tasks.py)
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from tasks import longtime_add
import time

if __name__ == '__main__':
    result = longtime_add.delay(1,2)
    # at this time, our task is not finished, so it will return False
    print 'Task finished? ', result.ready()
    print 'Task result: ', result.result
    # sleep 10 seconds to ensure the task has been finished
    time.sleep(10)
    # now the task should be finished and ready method will return True
    print 'Task finished? ', result.ready()
    print 'Task result: ', result.result
celery -A broker worker -l info
python run_tasks.py
posted on 2016-11-21 10:51 北京涛子 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/liujitao79/p/6084658.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值