functions
Cache-persistence helpers for the cst_calculation step (v1).
Extracted from cst_calculation_task to keep the cache-write orchestration
(building the cst_calculation.cache accessor and upserting the per-file rows)
apart from the task body.
Unlike the version-agnostic pure math in steps.cst_calculation.functions,
these are v1-specific and perform cache I/O: they bind to this version's
CSTCalculation ORM, CSTCalculationRecord, and CSTCalculationResult.
Module
Functions
build_cst_accessor
def build_cst_accessor( cache: CacheProtocol, task_hash: str, config: CSTCalculationConfig, *filter_fields: str,) ‑> CacheAccessor:Build the CacheAccessor for this step's cst_calculation partition.
Arguments
cache: The cache backend.task_hash: The step's partition key.config: The step config (source of any config-derived equality filters).*filter_fields: The step'scache_filter_fields— empty for this step, whose rows are keyed bytask_hashalone.
Returns
A CacheAccessor scoped to this task_hash.
persist_cst_metrics
def persist_cst_metrics( cache: CacheProtocol, task_hash: str, config: CSTCalculationConfig, output: dict[str, CSTMetrics | str | None], *, project_id: str | None = None, run_id: str | None = None, filter_fields: tuple[str, ...] = (),) ‑> CSTCalculationResult:Upsert per-file CST rows and return the cache-backed result.
Arguments
cache: The cache backend to persist into.task_hash: Partition key for thecst_calculationtable.config: The step config (passed through to the accessor).output: Per-file result map — aCSTMetrics(success), a reasonstr(missing_data:*/calculation_error:*, e.g. from the shared runner), orNone(the metric could not be computed for the file).project_id: Provenance only — not part of the cache key.run_id: Optional provenance run ID.filter_fields: The step'scache_filter_fields, forwarded to the accessor.
Returns
CSTCalculationResult carrying the row count and a scoped accessor.