-
Notifications
You must be signed in to change notification settings - Fork 5
Pass through --extra-settings to worker processes
#80
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import warnings | ||
| from typing import Any, Optional | ||
|
|
||
| from django.core.management.base import BaseCommand, CommandParser | ||
|
|
||
| from .utils import load_extra_settings | ||
| from .constants import SETTING_NAME_PREFIX | ||
|
|
||
|
|
||
| class CommandWithExtraSettings(BaseCommand): | ||
| """ | ||
| Base class for handling `--extra-settings`. | ||
|
|
||
| Derived classes must call `handle_extra_settings` at the top of their | ||
| `handle` method. For example: | ||
|
|
||
| class Command(CommandWithExtraSettings): | ||
| def handle(self, **options: Any) -> None: | ||
| super().handle_extra_settings(**options) | ||
| ... | ||
| """ | ||
|
|
||
| def add_arguments(self, parser: CommandParser) -> None: | ||
| super().add_arguments(parser) | ||
|
|
||
| extra_settings_group = parser.add_mutually_exclusive_group() | ||
| extra_settings_group.add_argument( | ||
| '--config', | ||
| action='store', | ||
| default=None, | ||
| help="The path to an additional django-style config file to load " | ||
| "(this spelling is deprecated in favour of '--extra-settings')", | ||
| ) | ||
| extra_settings_group.add_argument( | ||
| '--extra-settings', | ||
| action='store', | ||
| default=None, | ||
| help="The path to an additional django-style settings file to load. " | ||
| f"{SETTING_NAME_PREFIX}* settings discovered in this file will " | ||
| "override those from the default Django settings.", | ||
| ) | ||
|
|
||
| def handle_extra_settings( | ||
| self, | ||
| *, | ||
| config: Optional[str] = None, | ||
| extra_settings: Optional[str], | ||
| **_: Any | ||
| ) -> Optional[str]: | ||
| """ | ||
| Load extra settings if there are any. | ||
|
|
||
| Returns the filename (if any) of the extra settings that have been loaded. | ||
| """ | ||
|
|
||
| if config is not None: | ||
| warnings.warn( | ||
| "Use of '--config' is deprecated in favour of '--extra-settings'.", | ||
| category=DeprecationWarning, | ||
| ) | ||
| extra_settings = config | ||
|
|
||
| # Configuration overrides | ||
| if extra_settings is not None: | ||
| load_extra_settings(extra_settings) | ||
|
|
||
| return extra_settings |
40 changes: 4 additions & 36 deletions
40
django_lightweight_queue/management/commands/queue_configuration.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered just making this part of
handleon the super class and then having subclasses callsuper().handle(...)instead of a custom method?I can't see any weird side effects and it's probably a bit more expected when going through inheritance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did, unfortunately Django's
BaseCommand.handleraisesNotImplementedErrorso we'd need where to stop thesuper()calls to avoid errors and also means that callingsuper().handle(...)in an implementation could easily look like it's a bug.I also considered an approach of adding this functionality as a decorator (which would make it harder to get wrong) however that felt more complicated (class decorators being more complicated than function ones) and likely wouldn't have a great way to support the return value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right gotcha.