|
20 | 20 | PositiveInt, |
21 | 21 | SecretStr, |
22 | 22 | TypeAdapter, |
| 23 | + WrapValidator, |
23 | 24 | field_validator, |
24 | 25 | ) |
25 | 26 | from pydantic_settings import SettingsConfigDict |
@@ -284,13 +285,13 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings): |
284 | 285 | json_schema_extra={"auto_default_from_env": True} |
285 | 286 | ) |
286 | 287 |
|
287 | | - CLUSTERS_KEEPER_TASK_INTERVAL: Annotated[datetime.timedelta, BeforeValidator(int)] = Field( |
| 288 | + CLUSTERS_KEEPER_TASK_INTERVAL: datetime.timedelta = Field( |
288 | 289 | default=datetime.timedelta(seconds=30), |
289 | 290 | description="interval between each clusters clean check " |
290 | 291 | "(default to seconds, or see https://pydantic-docs.helpmanual.io/usage/types/#datetime-types for string formating)", |
291 | 292 | ) |
292 | 293 |
|
293 | | - SERVICE_TRACKING_HEARTBEAT: Annotated[datetime.timedelta, BeforeValidator(int)] = Field( |
| 294 | + SERVICE_TRACKING_HEARTBEAT: datetime.timedelta = Field( |
294 | 295 | default=datetime.timedelta(seconds=60), |
295 | 296 | description="Service heartbeat interval (everytime a heartbeat is sent into RabbitMQ) " |
296 | 297 | "(default to seconds, or see https://pydantic-docs.helpmanual.io/usage/types/#datetime-types for string formating)", |
@@ -334,8 +335,16 @@ def LOG_LEVEL(self) -> LogLevel: # noqa: N802 |
334 | 335 |
|
335 | 336 | @field_validator("CLUSTERS_KEEPER_LOGLEVEL") |
336 | 337 | @classmethod |
337 | | - def valid_log_level(cls, value: str) -> str: |
| 338 | + def _valid_log_level(cls, value: str) -> str: |
338 | 339 | return cls.validate_log_level(value) |
| 340 | + |
| 341 | + |
| 342 | + @field_validator("CLUSTERS_KEEPER_TASK_INTERVAL", "SERVICE_TRACKING_HEARTBEAT", mode="before") |
| 343 | + @classmethod |
| 344 | + def _validate_interval(cls, value: str | datetime.timedelta) -> int | datetime.timedelta: |
| 345 | + if isinstance(value, str): |
| 346 | + return int(value) |
| 347 | + return value |
339 | 348 |
|
340 | 349 |
|
341 | 350 | def get_application_settings(app: FastAPI) -> ApplicationSettings: |
|
0 commit comments