Skip to content

Example for using Celery 4 with Flask (App Factory) and Periodic Tasks with Celery Beat

Notifications You must be signed in to change notification settings

nebularazer/flask-celery-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Example for using Celery 4 with Flask (App Factory) and Periodic Tasks with Celery Beat

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages