Skip to content

Commit

Permalink
Merge pull request #154 from lsst-sqre/tickets/DM-42937
Browse files Browse the repository at this point in the history
DM-42937: Accept timedelta config values as strings
  • Loading branch information
rra authored Feb 20, 2024
2 parents a60206f + f0babff commit 5a262f1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/vocutouts/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from datetime import timedelta
from pathlib import Path

from pydantic import Field, PostgresDsn
from pydantic import Field, PostgresDsn, field_validator
from pydantic_settings import BaseSettings, SettingsConfigDict
from safir.logging import LogLevel, Profile

Expand Down Expand Up @@ -91,6 +91,18 @@ class Config(BaseSettings):
env_prefix="CUTOUT_", case_sensitive=False
)

@field_validator("lifetime", "sync_timeout", "timeout", mode="before")
@classmethod
def _parse_as_seconds(cls, v: int | str | timedelta) -> int | timedelta:
"""Convert timedelta strings so they are parsed as seconds."""
if isinstance(v, timedelta):
return v
try:
return int(v)
except ValueError as e:
msg = f"value {v} must be an integer number of seconds"
raise ValueError(msg) from e

def uws_config(self) -> UWSConfig:
"""Convert to configuration for the UWS subsystem."""
return UWSConfig(
Expand Down

0 comments on commit 5a262f1

Please sign in to comment.