flask-celery-example
flask-celery-example copied to clipboard
Example for using Celery 4 with Flask (App Factory) and Periodic Tasks with Celery Beat
flask-celery-example
An example to run flask with celery including:
- app factory setup
- send a long running task from flask app
- send periodic tasks with celery beat
based on flask-celery-example by Miguel Grinberg and his bloc article
endpoints
- / adds a task to the queue and schedule it to start in 10 seconds
- /message - shows messages in the database (revered every 10 seconds by celery task)
- /status/<task_id> - show the status of the long running task
installation
install dependencies with poetry
poetry install
poetry shell
start redis backend (using docker)
docker run -d --name redis -p 6379:6379 redis
run celery worker
source .env
celery -A src.worker:celery worker --loglevel=DEBUG
run celery beat for periodic tasks
source .env
celery -A src.worker:celery beat --loglevel=INFO
run flask app
source .env
# check the available routes
flask routes
# start flask development server
flask run