All Projects → zenyui → celery-flask-factory

zenyui / celery-flask-factory

Licence: MIT license
Implementing Celery within a Flask application factory

Programming Languages

python
139335 projects - #7 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to celery-flask-factory

antinex-core
Network exploit detection using highly accurate pre-trained deep neural networks with Celery + Keras + Tensorflow + Redis
Stars: ✭ 19 (-47.22%)
Mutual labels:  celery
sarjitsu
dockerized setup for visualizing System Activity Report (SAR) data.
Stars: ✭ 20 (-44.44%)
Mutual labels:  celery
python-flask-celery-example
Flask Rest API with the use of Celery
Stars: ✭ 41 (+13.89%)
Mutual labels:  celery
python-asynchronous-tasks
😎Asynchronous tasks in Python with Celery + RabbitMQ + Redis
Stars: ✭ 37 (+2.78%)
Mutual labels:  celery
celery-serverless
AWS Lambda running a Celery worker. Should be compatible with Google Functions and friends via Serverless too.
Stars: ✭ 29 (-19.44%)
Mutual labels:  celery
flickr to google photos migration
A tool for migrating your photo library from Flickr to Google Photos
Stars: ✭ 39 (+8.33%)
Mutual labels:  celery
celery-kubernetes-example
Small Flask app with scalable, asynchronous backend workers deployed on Kubernetes.
Stars: ✭ 79 (+119.44%)
Mutual labels:  celery
resin-home-automator
Example Python Flask web app deployable via resin.io for periodic Celery tasks
Stars: ✭ 18 (-50%)
Mutual labels:  celery
django-learning-pathway
(Currently in development) Learning pathways for learning Django.
Stars: ✭ 35 (-2.78%)
Mutual labels:  celery
lightflow
A lightweight, distributed workflow system
Stars: ✭ 67 (+86.11%)
Mutual labels:  celery
celery-beatx
Modern fail-safety scheduler for Celery
Stars: ✭ 46 (+27.78%)
Mutual labels:  celery
leek
Celery Tasks Monitoring Tool
Stars: ✭ 77 (+113.89%)
Mutual labels:  celery
flask-docker-compose
Flask application development skeleton with docker-compose
Stars: ✭ 22 (-38.89%)
Mutual labels:  celery
cyme
Celery Instance Manager
Stars: ✭ 50 (+38.89%)
Mutual labels:  celery
Online-Judge
Online Judge for hosting coding competitions inside NIT Durgapur made by GNU/Linux Users' Group!
Stars: ✭ 19 (-47.22%)
Mutual labels:  celery
lokole
Source code for the Lokole project. Lokole enables communities in the Congo DRC to pool resources to access efficient communication via email at an affordable price.
Stars: ✭ 37 (+2.78%)
Mutual labels:  celery
LazyBlacksmith
EVE Online Industry app written in python (flask) for backend, html / css / js for frontend
Stars: ✭ 44 (+22.22%)
Mutual labels:  celery
flask-celery-sqlalchemy
An example app to show how to get Flask, Celery, and SQLAlchemy working together
Stars: ✭ 33 (-8.33%)
Mutual labels:  celery
immuni-backend-analytics
Repository for the backend analytics
Stars: ✭ 39 (+8.33%)
Mutual labels:  celery
IATI.cloud
The open-source IATI datastore for IATI data with RESTful web API providing XML, JSON, CSV output. It extracts and parses IATI XML files referenced in the IATI Registry and powered by Apache Solr.
Stars: ✭ 35 (-2.78%)
Mutual labels:  celery

Celery in a Flask Application Factory

Introduction

This repo demonstrates configuring the Celery task queue with Flask in the application factory pattern.

The Flask application factory pattern delays configuration until the WSGI server is started, which allows for secure, dynamic configuration files. The official Celery tutorials assume all configuration is available upon import, so this sample Flask server shows how to configure Celery in a factory pattern.

Specifically, this example provides:

  • support for late binding of the Broker URL
  • executing all celery tasks within an app context

Implementation details

This sample aims to simulate a realistic Flask server by employing Blueprints and separate files for view functions and celery task definitions.

The repo is organized as follows:

  • server/ is the app
    • server/core.py creates the application factory
    • server/controller/routes.py defines the endpoints
    • server/controller/tasks.py defines Celery tasks
  • entrypoint_api.py is a cli interface for starting the Flask app in debug mode
  • entrypoint_celery.py is the entrypoint for the Celery worker
  • requirements.txt is the list of python dependencies for pip
  • docker.env defines the environment variables for the app
  • docker-compose.yml defines the services
  • Dockerfile is the image for the app & celery worker

The Flask app exposes an API that accepts a POST request to /sleep/<seconds> to start an task and return its ID. To check on the status of that task, issue a GET request to /sleep/<task_id>. The featured task is a dummy function that sleeps for <seconds> time then returns a datetime.

Per the recommendations of Celery documentation, this Flask/Celery app was tested with RabbitMQ as the message broker and Redis as the results backend, although (in theory) it should accept any supported broker/backend.

This sample runs the services as Docker containers (see ./docker-compose.yml), but feel free to run locally or in the cloud if it is more convenient for your use case - just make sure you modify your URL's in the configuration file accordingly.

Configuration

This Flask server accepts configuration as environment variables, which are set by default in the file ./docker.env.

Configuration:

  • CELERY_BROKER_URL is the rabbitmq URL
  • CELERY_RESULT_BACKEND is the redis URL

Running the services

You can run this example by starting starting the services with docker-compose.

Pull and build all images:

docker-compose build

Start all the containers in the background

docker-compose up -d

To check on the state of the containers, run:

docker-compose ps

Observe the API and celery worker logs:

docker-compose logs -f api worker

Create a single 30-second sleep task

curl -X POST http://localhost:8080/sleep/30

Above command will return a <task_id>, which can be used to check on the status of that task:

curl -X GET localhost:8080/sleep/<task_id>

Cleanup

You can bring down all containers in this sample app with:

docker-compose down

To make sure they're gone, check with docker-compose ps

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].