refactor(cron): move the job text/id-list normalizers into cron/jobs_normalize.py
Moved unchanged, so the follow-up leaves cron/jobs.py smaller than main instead of growing it through the #82010 FILE_LINES waiver. cron.jobs imports them back, so cron/jobs_model_pin's late from cron.jobs import _normalize_job_optional_text still resolves. Refs #155355
This commit is contained in:
36
cron/jobs.py
36
cron/jobs.py
@@ -37,6 +37,9 @@ from cron.env_settings import cron_env_setting
|
||||
from cron.jobs_invariants import _validate_job_mode_invariants, validate_schedule_knobs
|
||||
from cron.jobs_tristate import normalize_catch_up as _normalize_catch_up, normalize_wrap_response
|
||||
from cron.jobs_model_pin import _main_model_pin
|
||||
from cron.jobs_normalize import (
|
||||
_normalize_base_url, _normalize_context_from, _normalize_failure_deliver, _normalize_job_optional_text,
|
||||
)
|
||||
from cron import jobs_time
|
||||
from cron.scheduler_ownership import _claim_owner_is_dead
|
||||
from cron import extra_fire, jobs_error_text, store_health
|
||||
@@ -1678,23 +1681,6 @@ def _normalize_workdir(workdir: Optional[str]) -> Optional[str]:
|
||||
return str(resolved)
|
||||
|
||||
|
||||
def _normalize_job_optional_text(
|
||||
value: Any, *, strip_trailing_slash: bool = False
|
||||
) -> Optional[str]:
|
||||
if not isinstance(value, str):
|
||||
return None
|
||||
return (value.strip().rstrip("/") if strip_trailing_slash else value.strip()) or None
|
||||
|
||||
|
||||
def _normalize_base_url(value: Any) -> Optional[str]:
|
||||
return _normalize_job_optional_text(value, strip_trailing_slash=True)
|
||||
|
||||
|
||||
def _normalize_str_list(items: Any) -> Optional[list[str]]:
|
||||
"""Non-blank stripped items of *items*, or None when nothing remains."""
|
||||
return [str(j).strip() for j in items if str(j).strip()] or None
|
||||
|
||||
|
||||
def _normalize_enabled_toolsets(value: Any) -> Optional[list[str]]:
|
||||
"""Per-job toolset allowlist. An explicitly-set EMPTY list means 'nothing allowed' and must
|
||||
persist as [] — normalizing it to None would read back as 'no restriction' (#82010). Absent
|
||||
@@ -1706,22 +1692,6 @@ def _normalize_enabled_toolsets(value: Any) -> Optional[list[str]]:
|
||||
return [str(j).strip() for j in value if str(j).strip()]
|
||||
|
||||
|
||||
def _normalize_context_from(value: Any) -> Optional[list[str]]:
|
||||
"""Accept a job id or a list of ids; anything else is None."""
|
||||
if isinstance(value, str):
|
||||
value = [value]
|
||||
return _normalize_str_list(value) if isinstance(value, list) else None
|
||||
|
||||
|
||||
def _normalize_failure_deliver(value: Any) -> Optional[str]:
|
||||
"""failure_deliver shares deliver's value grammar; flatten str/list like the tool layer's
|
||||
_normalize_deliver_param for direct create_job callers. Semantic validation happens at
|
||||
resolution time via the shared deliver path."""
|
||||
if isinstance(value, (list, tuple)):
|
||||
return ",".join(str(p).strip() for p in value if str(p).strip()) or None
|
||||
return _normalize_job_optional_text(value)
|
||||
|
||||
|
||||
def _normalize_reasoning_effort(value: Any) -> Optional[str]:
|
||||
"""Spelling-only validation via the shared parser (cron knob never stricter/looser than
|
||||
config.yaml); model capability is deliberately NOT checked (model unknowable at create time,
|
||||
|
||||
35
cron/jobs_normalize.py
Normal file
35
cron/jobs_normalize.py
Normal file
@@ -0,0 +1,35 @@
|
||||
"""Text and id-list normalizers for ``create_job`` / ``update_job`` fields (moved from cron/jobs.py unchanged)."""
|
||||
from typing import Any, Optional
|
||||
|
||||
|
||||
def _normalize_job_optional_text(
|
||||
value: Any, *, strip_trailing_slash: bool = False
|
||||
) -> Optional[str]:
|
||||
if not isinstance(value, str):
|
||||
return None
|
||||
return (value.strip().rstrip("/") if strip_trailing_slash else value.strip()) or None
|
||||
|
||||
|
||||
def _normalize_base_url(value: Any) -> Optional[str]:
|
||||
return _normalize_job_optional_text(value, strip_trailing_slash=True)
|
||||
|
||||
|
||||
def _normalize_str_list(items: Any) -> Optional[list[str]]:
|
||||
"""Non-blank stripped items of *items*, or None when nothing remains."""
|
||||
return [str(j).strip() for j in items if str(j).strip()] or None
|
||||
|
||||
|
||||
def _normalize_context_from(value: Any) -> Optional[list[str]]:
|
||||
"""Accept a job id or a list of ids; anything else is None."""
|
||||
if isinstance(value, str):
|
||||
value = [value]
|
||||
return _normalize_str_list(value) if isinstance(value, list) else None
|
||||
|
||||
|
||||
def _normalize_failure_deliver(value: Any) -> Optional[str]:
|
||||
"""failure_deliver shares deliver's value grammar; flatten str/list like the tool layer's
|
||||
_normalize_deliver_param for direct create_job callers. Semantic validation happens at
|
||||
resolution time via the shared deliver path."""
|
||||
if isinstance(value, (list, tuple)):
|
||||
return ",".join(str(p).strip() for p in value if str(p).strip()) or None
|
||||
return _normalize_job_optional_text(value)
|
||||
Reference in New Issue
Block a user