泡面师

  • 首页
  • 记录
好记性不如烂笔头
  1. 首页
  2. 记录
  3. python
  4. 正文

centos下Flask使用任务队列celery

2018-06-10 4146点热度 3人点赞 0条评论

centos 7安装redis

yum install redis

python安装redis模块

pip install redis

安装celery

pip install celery

test.py

#encoding:utf-8
from flask import Flask
from celery import Celery

app = Flask(__name__)

app.config['CELERY_BROKER_URL'] = 'redis://localhost:6379'
app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost:6379/0'

celery = Celery('test', broker=app.config['CELERY_BROKER_URL'],backend=app.config['CELERY_RESULT_BACKEND'])
celery.conf.update(app.config)

@celery.task()
def test(a, b):
     return str(a+b)

@app.route('/test')
def test():
    task = test.delay(10, 20)
    return str(task)

if __name__ == '__main__':
    app.run(debug=True,host='127.0.0.1',port=5000)

运行

python test.py
在test.py同级目录运行celery -A test.celery worker -l info
访问http://127.0.0.1:5000/test
标签: celery Flask redis
最后更新:2018-06-10

泡面师

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

取消回复

COPYRIGHT © 2024 泡面师. ALL RIGHTS RESERVED.

THEME KRATOS MADE BY VTROIS