a simple Flask app template for Redis 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/
It's based on a simple Flask template, check here: https://github.com/kevinqqnj/flask-template-simple
- Simple but full structured Flask template to support RQ (Redis Queue)
- integrated with RQ, redis
- use Vue.js as frontend (you can replace as whatever frontend you like)
- frontend shows dashboard of queued tasks
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
# 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 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
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
For production app, you can easily expand functions as you wish, such as:
- Flask_Compress
- Flask_Cache
- Flask_Admin
- Flask_Security
- flask-template-advanced
For a detailed explanation on how things work, check out the guide (CHN).