Skip to content

Commit

Permalink
remove imports
Browse files Browse the repository at this point in the history
  • Loading branch information
mcucchi9 committed Oct 10, 2024
1 parent e47daaf commit 2744188
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions cads_processing_api_service/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

import os
import random
from typing import Annotated

import pydantic
import pydantic_settings
import structlog

Expand Down Expand Up @@ -63,24 +61,22 @@
)


def load_download_nodes(v: list[str], info: pydantic.ValidationInfo) -> list[str]:
v = []
file_path = info.data.get("download_nodes_file")
if file_path:
try:
with open(file_path, "r") as file:
for line in file:
if download_node := os.path.expandvars(line.rstrip("\n")):
v.append(download_node)
except Exception as e:
logger.warning(
"Failed to load download nodes from file",
file_path=file_path,
error=e,
)
if not v:
raise ValueError(f"No download nodes found in file {file_path}")
return v
def load_download_nodes(download_nodes_file: str) -> list[str]:
download_nodes = []
try:
with open(download_nodes_file, "r") as file:
for line in file:
if download_node := os.path.expandvars(line.rstrip("\n")):
download_nodes.append(download_node)
except Exception as e:
logger.warning(
"Failed to load download nodes from file",
file_path=download_nodes_file,
error=e,
)
if not download_nodes:
raise ValueError(f"No download nodes found in file {download_nodes_file}")
return download_nodes


class Settings(pydantic_settings.BaseSettings):
Expand Down Expand Up @@ -117,13 +113,11 @@ def profiles_api_url(self) -> str:
)

download_nodes_file: str = "/etc/retrieve-api/download-nodes.config"
download_nodes: Annotated[
list[str], pydantic.BeforeValidator(load_download_nodes)
] = []

@property
def download_node(self) -> str:
return random.choice(self.download_nodes)
download_nodes = load_download_nodes(self.download_nodes_file)
return random.choice(download_nodes)


settings = Settings()

0 comments on commit 2744188

Please sign in to comment.