This repository contains the example code for my blog article Using Celery with Flask.
The application provides two examples of background tasks using Celery:
- Example 1 sends emails asynchronously.
- Example 2 launches one or more asynchronous jobs and shows progress updates in the web page.
Here is a screenshot of this application:
- Clone 本项目.
- 创建 virtualenv(python3.6.7) 并且安装 requirements.
- 安装并启动 redis (如果是在 Linux or Mac 上, 执行
run-redis.sh
来安装并启动 redis). - 在项目根目录下创建.env 文件,用于存储环境变量
示例:
REDIS_URL=redis://127.0.0.1:6379/0
- 启动 Celery worker:
celery worker -A celery_worker.celery --loglevel=info
. - 启动 app:
venv/bin/python manage.py runserver
. - 浏览器访问
http://localhost:5000/
- 演示: