Flask with Redis RQ (template and deploy to Heroku)

Flask app template - RQ

a simple Flask app template for task queue.
working with python3.
Thanks to: Benjamin Bertrand https://beenje.github.io/blog/posts/running-background-tasks-with-flask-and-rq/

Live Demo: https://flaskrq.herokuapp.com/
Github: https://github.com/kevinqqnj/flask-template-rq

image.png

It's based on a simple Flask template, check here: https://github.com/kevinqqnj/flask-template-simple

Features:

  • Simple but full struct of Flask template to support RQ
  • integrated with RQ, redis
  • use Vue.js as frontend (you can replace as whatever frontend you like)
  • frontend shows dashboard of queued tasks
image.png

Prerequisite

You should have Redis installed.

Ubuntu:

sudo wget http://download.redis.io/redis-stable.tar.gz
sudo tar xzf redis-stable.tar.gz
cd redis-stable
sudo make
sudo make install

Windows: using Cygwin: https://www.jianshu.com/p/28960f5b1464

Install

# git clone
# create virtual env
python3 -m venv venv
source venv/bin/activate
# install python modules
pip3 install -r requirements.txt

Set redis server address in /config.py, default is: REDISTOGO_URL = os.getenv('REDISTOGO_URL', 'redis://localhost:6379')

Start up

# start Redis server
redis-server &
# run rq worker
python manage.py runworker
# run http server in anther terminal
python manage.py runserver

Bingo! Check app in your web browser at: http://localhost:5000

deploy to Heroku Server

ready for deploy to Heroku Procfile, heroku.sh and runtime.txt are included. It will use one dyno to run both worker and http server.

create app in heroku
choose "REDISTOGO" or "Heroku REDIS" from resource
git push to heroku
configure env. variables

refer to: https://devcenter.heroku.com/articles/getting-started-with-python

Expansion

For production app, you can easily expand functions as you wish, such as:

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容