1- import warnings
21from typing import Any , Dict , Optional
32
43import daemonize
54
65from 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
127
138from ...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
2010from ...runner import runner
21- from ...constants import SETTING_NAME_PREFIX
11+ from ...command_utils import CommandWithExtraSettings
2212from ...machine_types import Machine , PooledMachine , DirectlyConfiguredMachine
2313
2414
25- class Command (BaseCommand ):
15+ class Command (CommandWithExtraSettings ):
2616 def add_arguments (self , parser : CommandParser ) -> None :
17+ super ().add_arguments (parser )
18+
2719 parser .add_argument (
2820 '--pidfile' ,
2921 action = 'store' ,
@@ -58,22 +50,6 @@ def add_arguments(self, parser: CommandParser) -> None:
5850 default = None ,
5951 help = "Only run the given queue, useful for local debugging" ,
6052 )
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- )
7753 parser .add_argument (
7854 '--exact-configuration' ,
7955 action = 'store_true' ,
@@ -83,19 +59,11 @@ def add_arguments(self, parser: CommandParser) -> None:
8359 " '--of'." ,
8460 )
8561
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 :
9563 if options ['exact_configuration' ]:
96- if not options [ 'extra_settings' ] :
64+ if not had_extra_settings :
9765 raise CommandError (
98- "Must provide a value for '--config ' when using "
66+ "Must provide a value for '--extra-settings ' when using "
9967 "'--exact-configuration'." ,
10068 )
10169
@@ -127,19 +95,19 @@ def validate_and_normalise(self, options: Dict[str, Any]) -> None:
12795 def handle (self , ** options : Any ) -> None :
12896 logger = get_logger ('dlq.master' )
12997
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+ )
131104
132105 def touch_filename (name : str ) -> Optional [str ]:
133106 try :
134107 return options ['touchfile' ] % name
135108 except TypeError :
136109 return None
137110
138- # Configuration overrides
139- extra_config = options ['extra_settings' ]
140- if extra_config is not None :
141- load_extra_settings (extra_config )
142-
143111 logger .info ("Starting queue master" )
144112
145113 # Ensure children will be able to import our backend
@@ -164,7 +132,7 @@ def touch_filename(name: str) -> Optional[str]:
164132 )
165133
166134 def run () -> None :
167- runner (touch_filename , machine , logger )
135+ runner (touch_filename , machine , logger , extra_settings )
168136
169137 # fork() only after we have started enough to catch failure, including
170138 # being able to write to our pidfile.
0 commit comments