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

feat: added possibility to toggle background cache system #202

Merged
merged 2 commits into from
Oct 15, 2024

Conversation

TeKrop
Copy link
Owner

@TeKrop TeKrop commented Oct 14, 2024

Summary by Sourcery

Add a feature to toggle the background cache refresh system via a configuration setting. Implement a check in the main script to log a warning and exit if the system is disabled. Update tests to ensure the background cache refresh system is enabled during execution.

New Features:

  • Introduce a toggle for enabling or disabling the background cache refresh system through a new configuration setting.

Enhancements:

  • Add a warning log and exit the script if the background cache refresh system is disabled.

Tests:

  • Add a fixture to automatically set the background cache refresh system as enabled during tests.

@TeKrop TeKrop added the enhancement New feature or request label Oct 14, 2024
@TeKrop TeKrop self-assigned this Oct 14, 2024
Copy link
Contributor

sourcery-ai bot commented Oct 14, 2024

Reviewer's Guide by Sourcery

This pull request adds the ability to toggle the background cache refresh system. It introduces a new configuration setting, updates the main cache update script to respect this setting, and adds a corresponding test fixture.

Sequence diagram for cache update process with toggle

sequenceDiagram
    participant User
    participant Script as check_and_update_cache.py
    participant Settings
    participant Logger
    User->>Script: Run main()
    Script->>Settings: Check background_cache_refresh_enabled
    alt Background cache refresh enabled
        Script->>Logger: Log "Starting Redis cache update..."
        Script->>Script: get_soon_expired_cache_keys()
    else Background cache refresh disabled
        Script->>Logger: Log "Background Cache Refresh system is disabled"
        Script->>User: Raise SystemExit
    end
Loading

Class diagram for updated Settings class

classDiagram
    class Settings {
        +bool background_cache_refresh_enabled
        +str api_cache_key_prefix
    }
    note for Settings "New attribute background_cache_refresh_enabled added to toggle background cache refresh system."
Loading

File-Level Changes

Change Details Files
Added a new configuration setting to enable/disable background cache refresh
  • Introduced a new boolean setting 'background_cache_refresh_enabled' with a default value of True
  • Added the setting to the Settings class in the configuration file
app/config.py
Updated the main cache update script to respect the new background cache refresh setting
  • Added a condition to check if background cache refresh is enabled at the start of the main function
  • If disabled, the script logs a warning and exits
app/commands/check_and_update_cache.py
Added a test fixture to set background cache refresh as enabled for tests
  • Created a new pytest fixture named '_set_background_cache_refresh_enabled'
  • The fixture patches the 'background_cache_refresh_enabled' setting to True for tests
tests/commands/test_check_and_update_cache.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @TeKrop - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider improving the error handling in the main() function. Raising a SystemExit might be too abrupt; a more graceful shutdown or alternative behavior when background refresh is disabled could be beneficial.
  • It would be helpful to add some documentation or comments explaining the purpose and implications of disabling the background cache refresh system, especially in the Settings class where the new flag is introduced.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +35 to +41
@pytest.fixture(autouse=True)
def _set_background_cache_refresh_enabled():
with patch(
"app.common.cache_manager.settings.background_cache_refresh_enabled",
True,
):
yield
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): New fixture added for background cache refresh setting

This fixture sets the background_cache_refresh_enabled setting to True for all tests in this file. Consider adding tests that cover the case when this setting is False to ensure the new functionality is fully tested.

@pytest.fixture(autouse=True)
def background_cache_refresh_setting(request):
    def set_value(value):
        with patch("app.common.cache_manager.settings.background_cache_refresh_enabled", value):
            yield

    if request.param:
        yield from set_value(True)
    else:
        yield from set_value(False)

@pytest.mark.parametrize("background_cache_refresh_setting", [True, False], indirect=True)

Copy link

@TeKrop TeKrop merged commit 7c6b6a3 into main Oct 15, 2024
3 checks passed
@TeKrop TeKrop deleted the feat/background-cache-system-toggle branch October 15, 2024 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant