Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-44763: Support human-readable timedelta strings #178

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.d/20240613_201328_rra_DM_44763.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### New features

- Support human-readable `4h30m20s`-style strings for `CUTOUT_LIFETIME` and `CUTOUT_SYNC_TIMEOUT` in addition to numbers of seconds.
13 changes: 5 additions & 8 deletions src/vocutouts/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
)
from pydantic_settings import BaseSettings, SettingsConfigDict
from safir.arq import ArqMode
from safir.datetime import parse_timedelta
from safir.logging import LogLevel, Profile

from .dependencies import get_params_dependency, post_params_dependency
Expand Down Expand Up @@ -181,15 +182,11 @@ def _validate_arq_queue_url(cls, v: RedisDsn) -> RedisDsn:

@field_validator("lifetime", "sync_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):
def _parse_timedelta(cls, v: str | float | timedelta) -> float | timedelta:
"""Support human-readable timedeltas."""
if not isinstance(v, str):
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
return parse_timedelta(v)

@property
def arq_redis_settings(self) -> RedisSettings:
Expand Down