Clean runtime code
This commit is contained in:
@@ -48,9 +48,7 @@ class MobileDeSyncDetailRequest(BaseModel):
|
||||
class MobileDeEnrichImagesRequest(BaseModel):
|
||||
lane: str = "mobile_de_cars"
|
||||
batch_size: int = 10
|
||||
max_existing_images: int = 1
|
||||
staleness_hours: int = 168
|
||||
delay_seconds: float = 1.0
|
||||
|
||||
|
||||
class MobileDeRuntimeSegmentsRequest(BaseModel):
|
||||
|
||||
@@ -155,7 +155,6 @@ class ProxyConfig:
|
||||
|
||||
@dataclass(slots=True)
|
||||
class Settings:
|
||||
headless: bool = _env_bool("MOBILEDE_HEADLESS", True)
|
||||
log_level: str = _env_str("MOBILEDE_LOG_LEVEL", "INFO")
|
||||
runtime_config_file: str | None = _env_path_str("MOBILEDE_RUNTIME_CONFIG_FILE")
|
||||
listing: ListingConfig = field(default_factory=ListingConfig)
|
||||
|
||||
@@ -1,20 +1,5 @@
|
||||
import logging
|
||||
import sys
|
||||
from contextvars import ContextVar
|
||||
|
||||
# Trace ID текущего потока или корутины.
|
||||
TRACE_ID: ContextVar[str] = ContextVar("trace_id", default="-")
|
||||
|
||||
|
||||
class TraceIdFilter(logging.Filter):
|
||||
# Добавляет trace_id в запись лога.
|
||||
def filter(self, record: logging.LogRecord) -> bool:
|
||||
record.trace_id = TRACE_ID.get()
|
||||
return True
|
||||
|
||||
|
||||
def set_trace_id(trace_id: str) -> None:
|
||||
TRACE_ID.set(trace_id)
|
||||
|
||||
|
||||
def setup_logging(level: str = "INFO", log_file: str | None = None) -> None:
|
||||
@@ -22,9 +7,7 @@ def setup_logging(level: str = "INFO", log_file: str | None = None) -> None:
|
||||
handlers: list[logging.Handler] = [logging.StreamHandler(sys.stderr)]
|
||||
if log_file:
|
||||
handlers.append(logging.FileHandler(log_file, encoding="utf-8"))
|
||||
trace_filter = TraceIdFilter()
|
||||
for handler in handlers:
|
||||
handler.addFilter(trace_filter)
|
||||
handler.setLevel(getattr(logging, level.upper(), logging.INFO))
|
||||
root = logging.getLogger()
|
||||
root.setLevel(getattr(logging, level.upper(), logging.INFO))
|
||||
|
||||
@@ -56,10 +56,6 @@ def _optional_bool(value: Any) -> bool | None:
|
||||
@dataclass(slots=True)
|
||||
class RuntimeSyncConfig:
|
||||
name: str | None = None
|
||||
ids_initial_size: int | None = None
|
||||
ids_next_size: int | None = None
|
||||
ids_max_pages: int | None = None
|
||||
condition_check_enabled: bool | None = None
|
||||
lane: str | None = None
|
||||
only_new: bool | None = None
|
||||
limit: int | None = None
|
||||
@@ -71,10 +67,6 @@ class RuntimeSyncConfig:
|
||||
lane = str(data.get("lane")).strip() if data.get("lane") else None
|
||||
return cls(
|
||||
name=name or None,
|
||||
ids_initial_size=_optional_int(data.get("ids_initial_size")),
|
||||
ids_next_size=_optional_int(data.get("ids_next_size")),
|
||||
ids_max_pages=_optional_int(data.get("ids_max_pages")),
|
||||
condition_check_enabled=_optional_bool(data.get("condition_check_enabled")),
|
||||
lane=lane or None,
|
||||
only_new=_optional_bool(data.get("only_new")),
|
||||
limit=_optional_int(data.get("limit")),
|
||||
@@ -349,27 +341,18 @@ class RuntimeMobileDeSegment:
|
||||
class RuntimeMobileDeEnrichmentConfig:
|
||||
enabled: bool = True
|
||||
batch_size: int = 10
|
||||
max_existing_images: int = 1
|
||||
staleness_hours: int = 168
|
||||
delay_seconds: float = 1.0
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict[str, Any] | None) -> "RuntimeMobileDeEnrichmentConfig":
|
||||
data = data or {}
|
||||
enabled = _optional_bool(data.get("enabled"))
|
||||
batch_size = _optional_int(data.get("batch_size"))
|
||||
max_existing_images = _optional_int(data.get("max_existing_images"))
|
||||
staleness_hours = _optional_int(data.get("staleness_hours"))
|
||||
try:
|
||||
delay_seconds = float(data.get("delay_seconds", 1.0))
|
||||
except (TypeError, ValueError):
|
||||
delay_seconds = 1.0
|
||||
return cls(
|
||||
enabled=True if enabled is None else enabled,
|
||||
batch_size=max(1, 10 if batch_size is None else batch_size),
|
||||
max_existing_images=max(0, 1 if max_existing_images is None else max_existing_images),
|
||||
staleness_hours=max(0, 168 if staleness_hours is None else staleness_hours),
|
||||
delay_seconds=max(0.0, delay_seconds),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user