14
14
15
15
"""Wrapper for rqworker command."""
16
16
17
+ import logging
18
+
19
+ from dispatcherd import run_service as run_dispatcherd_service
20
+ from dispatcherd .config import setup as dispatcherd_setup
17
21
from django .conf import settings
18
22
from django .core .management .base import BaseCommand , CommandParser
19
23
from django_rq .management .commands import rqworker
20
24
21
25
from aap_eda .settings import features
22
26
27
+ logger = logging .getLogger (__name__ )
28
+
23
29
24
30
class Command (BaseCommand ):
25
31
"""Wrapper for rqworker command.
@@ -35,12 +41,33 @@ def add_arguments(self, parser: CommandParser) -> None:
35
41
36
42
def handle (self , * args , ** options ) -> None :
37
43
if features .DISPATCHERD :
38
- self .stderr .write (
39
- self .style .ERROR (
40
- "DISPATCHERD feature not implemented yet. "
41
- f"Please disable { settings .DISPATCHERD_FEATURE_FLAG_NAME } "
42
- "in your settings." ,
43
- )
44
+ return self ._handle_dispatcherd (* args , ** options )
45
+
46
+ # run rqworker command if dispatcherd is not enabled
47
+ logger .info ("Starting worker with rqworker." )
48
+ return rqworker .Command .handle (self , * args , ** options )
49
+
50
+ def _handle_dispatcherd (self , * args , ** options ) -> None :
51
+ """Handle dispatcherd service."""
52
+ if "worker_class" not in options :
53
+ self .style .ERROR ("Missing required argument: --worker-class" )
54
+ raise SystemExit (1 )
55
+
56
+ # Use rqworker expected args to determine worker type
57
+ if "ActivationWorker" in options ["worker_class" ]:
58
+ dispatcherd_setup (
59
+ settings .DISPATCHERD_ACTIVATION_WORKER_SETTINGS ,
60
+ )
61
+
62
+ elif "DefaultWorker" in options ["worker_class" ]:
63
+ dispatcherd_setup (settings .DISPATCHERD_DEFAULT_WORKER_SETTINGS )
64
+ else :
65
+ self .style .ERROR (
66
+ "Invalid worker class. "
67
+ "Please use either ActivationWorker or DefaultWorker."
44
68
)
45
69
raise SystemExit (1 )
46
- return rqworker .Command .handle (self , * args , ** options )
70
+
71
+ logger .info ("Starting worker with dispatcherd." )
72
+ run_dispatcherd_service ()
73
+ return None
0 commit comments