Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comprehensive Celery Integration Enhancement in FastAPI Boilerplate #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

marcosmamorim
Copy link

@marcosmamorim marcosmamorim commented May 26, 2024

Comprehensive Celery Integration Enhancement in FastAPI Boilerplate

Overview

This PR introduces a significant enhancement to the Celery integration mechanism within the FastAPI Boilerplate project. The changes aim to streamline task management and improve the efficiency of background task processing by sharing database session configurations between FastAPI and Celery components.

Key Changes

  • CeleryConfigurator Class: A new class that centralizes all Celery configurations, facilitating easier maintenance and updates.
  • Dynamic Queue Configuration: Automatically configures Celery queues based on the project's module structure. This dynamic setup scans for tasks.py files within each module's app/*/application/celery directory, creating a dedicated queue for each module found. This approach eliminates the need for manual queue setup and enhances scalability.
  • Shared Session Management: Integrates database session management between FastAPI and Celery, ensuring that both components handle sessions in a unified manner. This reduces the overhead associated with session management and minimizes potential for errors.

Benefits

  • Improved Scalability: As the project grows, the new setup automatically adapts, adding necessary task queues without manual configuration.
  • Enhanced Maintainability: Centralizing configuration reduces complexity and makes the system easier to understand and modify.
  • Consistency Across Components: By sharing session management logic, the system behaves consistently whether tasks are executed synchronously or asynchronously.

Usage Example

With the new setup, adding a new module with background tasks only requires adding a tasks.py file in the correct directory. The system automatically handles the rest, setting up queues and ensuring the tasks are correctly routed and executed.

… Boilerplate

This commit overhauls the Celery integration within the FastAPI Boilerplate project
by introducing a new class, `CeleryConfigurator`, which centralizes the configuration of Celery.

This includes dynamic queue setup based on the presence of `tasks.py` in module subdirectories,
ensuring scalability and maintainability.

Additionally, the integration now seamlessly manages database sessions between FastAPI and Celery,
sharing session handling logic to reduce redundancy and improve performance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants