@@ -50,6 +50,7 @@ class HyperglassSettings(BaseSettings):
5050 port : int = 8001
5151 ca_cert : t .Optional [FilePath ] = None
5252 container : bool = False
53+ workers : t .Optional [int ] = None
5354
5455 def __init__ (self , ** kwargs ) -> None :
5556 """Create hyperglass Settings instance."""
@@ -78,6 +79,7 @@ def __rich_console__(self, console: "Console", options: "ConsoleOptions") -> "Re
7879 "redis_dsn" ,
7980 "host" ,
8081 "port" ,
82+ "workers" ,
8183 )
8284 )
8385 for attr in params :
@@ -135,12 +137,22 @@ def log_level(self: "HyperglassSettings") -> str:
135137 return "DEBUG"
136138 return "WARNING"
137139
138- @property
139- def workers (self : "HyperglassSettings" ) -> int :
140- """Get worker count, inferred from debug mode."""
141- if self .debug :
140+ @field_validator ("workers" , mode = "after" )
141+ def validate_workers (
142+ cls : "HyperglassSettings" , value : t .Optional [int ], info : ValidationInfo
143+ ) -> int :
144+ """Resolve worker count.
145+
146+ Precedence: explicit override (``HYPERGLASS_WORKERS`` / kwarg) > debug
147+ mode (1) > auto-detected ``cpu_count(2)`` capped at 8.
148+ """
149+ if value is not None :
150+ if value < 1 :
151+ raise ValueError ("workers must be at least 1" )
152+ return value
153+ if info .data .get ("debug" ) is True :
142154 return 1
143- return cpu_count (2 )
155+ return min ( cpu_count (2 ), 8 )
144156
145157 @property
146158 def redis (self : "HyperglassSettings" ) -> t .Dict [str , t .Union [None , int , str ]]:
@@ -158,7 +170,7 @@ def redis(self: "HyperglassSettings") -> t.Dict[str, t.Union[None, int, str]]:
158170 @property
159171 def redis_connection_pool (self : "HyperglassSettings" ) -> t .Dict [str , t .Any ]:
160172 """Get Redis ConnectionPool keyword arguments."""
161- return {"url" : str (self .redis_dsn ), "max_connections" : at_least (8 , cpu_count ( 2 ) )}
173+ return {"url" : str (self .redis_dsn ), "max_connections" : at_least (8 , self . workers )}
162174
163175 @property
164176 def dev_url (self : "HyperglassSettings" ) -> str :
0 commit comments