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

Implement JSON Import Feature, Enhance Database Transactions, and Dockerize the Application #19

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

TheoZerbibi
Copy link

Description

This merge request introduces several key enhancements to the application, including a robust JSON import feature with real-time status tracking, improved database transaction management, and full Dockerization for streamlined deployment. These updates aim to enhance user experience, ensure data integrity, and simplify the deployment process.

1. JSON Import Feature with Status Tracking

  • Functionality:

    • Users can now import their settings via a JSON file through the profile settings page.
    • The import process supports real-time status updates, allowing users to monitor the progress of their import even if they refresh the page.
  • Implementation Details:

    • Frontend Enhancements:

      • Added file input and associated buttons for uploading JSON files.
      • Utilized sessionStorage to persist the import task ID, ensuring the import status remains visible across page refreshes.
      • Implemented JavaScript functions to handle file reading, validation, submission, and periodic status polling every 10 seconds.
      • Displayed import status messages and disabled the import button during active imports to prevent duplicate tasks.
    • Backend Enhancements:

      • Created new API endpoints /settings/import_json and /settings/import_status/<task_id> to handle import requests and status checks.
      • Implemented a task queue and worker thread to process import tasks asynchronously, ensuring the main application remains responsive.
      • Utilized SQL transactions to maintain data integrity during the import process, ensuring that all related database operations either complete successfully or are rolled back in case of errors.

2. Enhanced Database Transaction Management

  • Functionality:

    • Improved the Db class to use consistent attribute naming (self.conn instead of mixed self.conn and self.con), eliminating attribute errors.
    • Ensured that each thread or request handler creates its own instance of the Db class to prevent concurrent access issues with SQLite.
    • Incorporated context managers (with Db(...) as db:) to manage database connections and transactions safely, automatically handling commits and rollbacks.
  • Implementation Details:

    • Refactored the Db class to standardize the connection attribute and ensure all methods correctly reference self.conn.
    • Updated all routes and worker threads to instantiate the Db class within their execution context, promoting thread safety and preventing shared connection conflicts.
    • Added retry mechanisms for database operations prone to locking issues, enhancing the robustness of database interactions.

3. Dockerization of the Application

  • Functionality:
    • Containerized the entire application using Docker to facilitate consistent environments across development, testing, and production.
    • Simplified the setup process with Docker Compose, allowing for easy orchestration of multiple services such as the Flask application and the SQLite database.
  • Implementation Details:
    • Dockerfile:

      • Created a Dockerfile to define the application's Docker image, specifying the base image, dependencies, environment variables, and startup commands.
    • Docker Compose:

      • Developed a docker-compose.yml file to manage multi-container configurations, including the Flask app and any auxiliary services.
      • Configured volume mounts for persistent storage of the SQLite database and static files.
        Exposed necessary ports to allow external access to the application.
    • Configuration Adjustments:

      • Updated application configurations to accommodate running within Docker containers, such as setting appropriate environment variables and network settings.
      • Ensured that the database file is correctly referenced within the Docker environment.

Additional Notes

  • Documentation:
    • Update the project’s README and deployment guides to include instructions on using Docker and the new JSON import feature.
  • Proxy:
    • Rebind proxy image in routes/helpers.py, from https://friends42.fr/proxy/ to https://friends.42paris.fr/proxy/.

… setup

feat(app.py): implement database connection management using context manager for better resource handling
feat(f_front.py): add JSON import functionality for user settings with validation and task tracking
feat(f_locations.py): enhance location update route with token validation
feat(tasks.py): create background task processing for importing user settings with retry logic
style(helpers.py): clean up image proxy function for better readability
fix(updater.py): update URL for location updates to match new port configuration
style(settings.html): improve UI for settings page with import functionality and status display
…isting imports to enhance user experience during JSON import process
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.

1 participant