Flask Celery Example

screenshot of Flask Celery Example
flask

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

Overview:

Flask and Celery together create a powerful combination for developing web applications that can handle complex task management efficiently. The example project highlights a straightforward implementation, showcasing how to set up an app factory with Flask, send long-running tasks, and use Celery beat for periodic tasks. This approach not only improves performance but also makes applications more responsive by offloading time-consuming operations through asynchronous processing.

For developers who want to integrate Flask with Celery, this example provides an excellent starting point. It covers essential features to help users grasp how to leverage the capabilities of Celery for task management while working within a Flask environment, ensuring you can build responsive applications that seamlessly execute background jobs.

Features:

  • App Factory Setup: Easily create and configure your Flask application with an app factory pattern, promoting modular and testable application design.

  • Long Running Task Execution: Seamlessly send tasks that can run in the background, allowing your Flask app to remain responsive while processing heavy operations.

  • Periodic Task Scheduling with Celery Beat: Utilize Celery beat to run scheduled tasks at fixed intervals, perfect for performing repetitive tasks such as data cleanup or report generation.

  • Task Queue Integration: Add tasks to the queue through endpoints, managing how and when tasks are executed with a simple HTTP request.

  • Real-time Message Display: Store messages in a database and have them refreshed every 10 seconds through a dedicated Celery task, providing users with the most recent updates.

  • Task Status Checking: Easily check the status of long-running tasks with dedicated endpoints, providing feedback on task progression and completion.

  • Simple Dependency Management: Leverage Poetry for managing dependencies, simplifying the installation and setup process for the project.

  • Docker Compatibility: Start a Redis backend using Docker, ensuring that your Celery worker runs smoothly and efficiently without the hassle of local installations.

flask
Flask

Flask is a lightweight and popular web framework for Python, known for its simplicity and flexibility. It is widely used to build web applications, providing a minimalistic approach to web development with features like routing, templates, and support for extensions.