-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into allow-runtime-settings-overrides
- Loading branch information
Showing
13 changed files
with
216 additions
and
120 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
51 changes: 51 additions & 0 deletions
51
django_lightweight_queue/management/commands/queue_clear.py
This file contains 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,51 @@ | ||
import argparse | ||
|
||
from django.core.management.base import BaseCommand, CommandError | ||
|
||
from ...types import QueueName | ||
from ...utils import get_backend | ||
from ...backends.base import BackendWithClear | ||
|
||
|
||
class Command(BaseCommand): | ||
help = """ | ||
Command to clear work on a redis-backed queue. | ||
All pending jobs will be deleted from the queue. In flight jobs won't be | ||
affected. | ||
""" # noqa:A003 # inherited name | ||
|
||
def add_arguments(self, parser: argparse.ArgumentParser) -> None: | ||
parser.add_argument( | ||
'queue', | ||
action='store', | ||
help="The queue to pause.", | ||
) | ||
|
||
parser.add_argument( | ||
'--yes', | ||
dest='skip_prompt', | ||
action='store_true', | ||
help="Skip confirmation prompt.", | ||
) | ||
|
||
def handle(self, queue: QueueName, skip_prompt: bool = False, **options: object) -> None: | ||
|
||
backend = get_backend(queue) | ||
|
||
if not isinstance(backend, BackendWithClear): | ||
raise CommandError( | ||
"Configured backend '{}.{}' doesn't support clearing".format( | ||
type(backend).__module__, | ||
type(backend).__name__, | ||
), | ||
) | ||
|
||
if not skip_prompt: | ||
prompt = "Clear all jobs from queue {}) [y/N] ".format(queue) | ||
choice = input(prompt).lower() | ||
|
||
if choice != "y": | ||
raise CommandError("Aborting") | ||
|
||
backend.clear(queue) |
40 changes: 4 additions & 36 deletions
40
django_lightweight_queue/management/commands/queue_configuration.py
This file contains 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 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
Oops, something went wrong.