1
- import warnings
2
1
from typing import Any , Dict , Optional
3
2
4
3
import daemonize
5
4
6
5
from django .apps import apps
7
- from django .core .management .base import (
8
- BaseCommand ,
9
- CommandError ,
10
- CommandParser ,
11
- )
6
+ from django .core .management .base import CommandError , CommandParser
12
7
13
8
from ...types import QueueName
14
- from ...utils import (
15
- get_logger ,
16
- get_backend ,
17
- get_middleware ,
18
- load_extra_settings ,
19
- )
9
+ from ...utils import get_logger , get_backend , get_middleware
20
10
from ...runner import runner
21
- from ...constants import SETTING_NAME_PREFIX
11
+ from ...command_utils import CommandWithExtraSettings
22
12
from ...machine_types import Machine , PooledMachine , DirectlyConfiguredMachine
23
13
24
14
25
- class Command (BaseCommand ):
15
+ class Command (CommandWithExtraSettings ):
26
16
def add_arguments (self , parser : CommandParser ) -> None :
17
+ super ().add_arguments (parser )
18
+
27
19
parser .add_argument (
28
20
'--pidfile' ,
29
21
action = 'store' ,
@@ -58,22 +50,6 @@ def add_arguments(self, parser: CommandParser) -> None:
58
50
default = None ,
59
51
help = "Only run the given queue, useful for local debugging" ,
60
52
)
61
- extra_settings_group = parser .add_mutually_exclusive_group ()
62
- extra_settings_group .add_argument (
63
- '--config' ,
64
- action = 'store' ,
65
- default = None ,
66
- help = "The path to an additional django-style config file to load "
67
- "(this spelling is deprecated in favour of '--extra-settings')" ,
68
- )
69
- extra_settings_group .add_argument (
70
- '--extra-settings' ,
71
- action = 'store' ,
72
- default = None ,
73
- help = "The path to an additional django-style settings file to load. "
74
- f"{ SETTING_NAME_PREFIX } * settings discovered in this file will "
75
- "override those from the default Django settings." ,
76
- )
77
53
parser .add_argument (
78
54
'--exact-configuration' ,
79
55
action = 'store_true' ,
@@ -83,19 +59,11 @@ def add_arguments(self, parser: CommandParser) -> None:
83
59
" '--of'." ,
84
60
)
85
61
86
- def validate_and_normalise (self , options : Dict [str , Any ]) -> None :
87
- extra_config = options .pop ('config' )
88
- if extra_config is not None :
89
- warnings .warn (
90
- "Use of '--config' is deprecated in favour of '--extra-settings'." ,
91
- category = DeprecationWarning ,
92
- )
93
- options ['extra_settings' ] = extra_config
94
-
62
+ def validate_and_normalise (self , options : Dict [str , Any ], had_extra_settings : bool ) -> None :
95
63
if options ['exact_configuration' ]:
96
- if not options [ 'extra_settings' ] :
64
+ if not had_extra_settings :
97
65
raise CommandError (
98
- "Must provide a value for '--config ' when using "
66
+ "Must provide a value for '--extra-settings ' when using "
99
67
"'--exact-configuration'." ,
100
68
)
101
69
@@ -127,19 +95,19 @@ def validate_and_normalise(self, options: Dict[str, Any]) -> None:
127
95
def handle (self , ** options : Any ) -> None :
128
96
logger = get_logger ('dlq.master' )
129
97
130
- self .validate_and_normalise (options )
98
+ extra_settings = super ().handle_extra_settings (** options )
99
+
100
+ self .validate_and_normalise (
101
+ options ,
102
+ had_extra_settings = extra_settings is not None ,
103
+ )
131
104
132
105
def touch_filename (name : str ) -> Optional [str ]:
133
106
try :
134
107
return options ['touchfile' ] % name
135
108
except TypeError :
136
109
return None
137
110
138
- # Configuration overrides
139
- extra_config = options ['extra_settings' ]
140
- if extra_config is not None :
141
- load_extra_settings (extra_config )
142
-
143
111
logger .info ("Starting queue master" )
144
112
145
113
# Ensure children will be able to import our backend
@@ -164,7 +132,7 @@ def touch_filename(name: str) -> Optional[str]:
164
132
)
165
133
166
134
def run () -> None :
167
- runner (touch_filename , machine , logger )
135
+ runner (touch_filename , machine , logger , extra_settings )
168
136
169
137
# fork() only after we have started enough to catch failure, including
170
138
# being able to write to our pidfile.
0 commit comments