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

Allow to use maintenance while the migrations are in progress #2676

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

sainak
Copy link
Member

@sainak sainak commented Dec 22, 2024

Proposed Changes

  • Allow to use maintenance while the migrations are in progress

Merge Checklist

  • Tests added/fixed
  • Update docs in /docs
  • Linting Complete
  • Any other necessary step

Only PR's with test cases included and passing lint and test pipelines will be reviewed

@ohcnetwork/care-backend-maintainers @ohcnetwork/care-backend-admins

Summary by CodeRabbit

  • New Features

    • Introduced a more structured backend approach for managing maintenance mode.
    • Added new environment variables for rate limiting, SMS notifications, and cloud storage configurations.
    • Implemented a decorator to ensure maintenance mode is disabled for specific endpoints.
    • Enhanced script to handle maintenance mode during database migrations.
  • Bug Fixes

    • Adjusted script behavior to ensure proper toggling of maintenance mode during execution.

@sainak sainak requested a review from a team as a code owner December 22, 2024 17:00
Copy link

coderabbitai bot commented Dec 22, 2024

📝 Walkthrough

Walkthrough

The pull request introduces configuration changes focusing on maintenance mode management and environment-specific settings. The modifications enhance the application's flexibility by implementing a more structured backend approach for maintenance states, adding new environment variables, and introducing conditional maintenance mode handling in deployment scripts. These changes aim to provide more granular control over system configurations and operational states.

Changes

File Change Summary
config/settings/base.py - Replaced MAINTENANCE_MODE with MAINTENANCE_MODE_STATE_BACKEND
- Added environment variables for rate limiting, SMS, and cloud storage
config/views.py - Added @force_maintenance_mode_off decorator to ping function
scripts/celery_beat.sh - Implemented conditional maintenance mode handling
- Modified script execution flags

Sequence Diagram

sequenceDiagram
    participant Script as Celery Beat Script
    participant App as Django Application
    participant DB as Database

    alt AUTO_MAINTENANCE_MODE is true
        Script->>App: Enable Maintenance Mode
        Script->>DB: Run Migrations
        Script->>App: Disable Maintenance Mode
    else AUTO_MAINTENANCE_MODE is false
        Script->>DB: Run Migrations
    end
Loading

Poem

🛠️ Maintenance Mode, oh so fine
Backends dancing, line by line
Scripts that toggle, settings that shine
Flexibility's the new design
Code evolves, almost divine! 🚧

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
scripts/celery_beat.sh (1)

9-11: Consider adding error handling for maintenance mode operations.

While the maintenance mode toggle is well-placed, it might be good to add some error handling. You know, just in case something goes wrong during migrations (it never does, right? 😏).

 if [[ "${AUTO_MAINTENANCE_MODE}" == "true" ]]; then
-    python manage.py maintenance_mode on
+    if ! python manage.py maintenance_mode on; then
+        echo "Failed to enable maintenance mode"
+        exit 1
+    fi
 fi

 python manage.py migrate --noinput
 python manage.py compilemessages -v 0
 python manage.py load_redis_index

 if [[ "${AUTO_MAINTENANCE_MODE}" == "true" ]]; then
-    python manage.py maintenance_mode off
+    if ! python manage.py maintenance_mode off; then
+        echo "Failed to disable maintenance mode"
+        # Consider if you want to exit here or continue
+        exit 1
+    fi
 fi

Also applies to: 17-19

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fbf76d7 and b0121a1.

📒 Files selected for processing (3)
  • config/settings/base.py (1 hunks)
  • config/views.py (2 hunks)
  • scripts/celery_beat.sh (1 hunks)
🔇 Additional comments (2)
config/views.py (1)

4-6: LGTM! Smart choice keeping the health check endpoint accessible.

The addition of force_maintenance_mode_off decorator ensures that monitoring systems can still verify the application's heartbeat during maintenance windows.

Also applies to: 17-17

config/settings/base.py (1)

427-427: Good choice using CacheBackend for maintenance mode state.

Using the cache backend is more reliable for distributed environments and aligns well with the existing Redis configuration.

Let's verify the cache configuration is properly set up:

✅ Verification successful

Well, someone certainly did their homework with the cache configuration

The Redis cache backend is indeed properly configured, making the CacheBackend choice for maintenance mode quite appropriate. The setup includes:

  • A properly configured Redis cache as the default backend
  • Redis URL configuration with a sensible default
  • Test environment gracefully falling back to a dummy cache

I suppose we can all sleep better knowing the maintenance mode state will be reliably stored in Redis, synchronized across all instances. How... comforting.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify Redis cache configuration exists and is properly configured

# Check if Redis cache backend is configured
rg -A 5 "CACHES.*=.*{" config/settings/

Length of output: 129


Script:

#!/bin/bash
# Let's try a more precise search for cache configuration
rg -l "CACHES\s*=" config/settings/

# Also search for Redis-related configuration
rg -l "REDIS" config/settings/

# And check the actual content of base.py where we saw the maintenance mode config
cat config/settings/base.py | grep -A 10 -B 10 "MAINTENANCE_MODE"

Length of output: 1283


Script:

#!/bin/bash
# Let's see the actual cache configuration in both files
cat config/settings/base.py | grep -A 10 "CACHES\s*="
cat config/settings/test.py | grep -A 10 "CACHES\s*="

# And check if there's any Redis URL configuration
rg "REDIS_URL" config/settings/

Length of output: 1054

Copy link

codecov bot commented Dec 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.48%. Comparing base (fbf76d7) to head (b0121a1).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2676   +/-   ##
========================================
  Coverage    70.48%   70.48%           
========================================
  Files          201      201           
  Lines        11439    11439           
  Branches      1164     1164           
========================================
  Hits          8063     8063           
  Misses        3014     3014           
  Partials       362      362           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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