Skip to main content

functions

Cache-persistence helpers for the fluid_calculation step (v1).

Extracted from fluid_calculation_task to keep the cache-write orchestration (building the fluid_calculation.cache accessor and upserting the per-file rows) apart from the task body.

Unlike the version-agnostic pure math in steps.fluid_calculation.functions, these are v1-specific and perform cache I/O: they bind to this version's FluidCalculation ORM, FluidCalculationRecord, and FluidCalculationResult.

Module

Functions

build_fluid_accessor

def build_fluid_accessor(    cache: CacheProtocol,    task_hash: str,    config: FluidCalculationConfig,    *filter_fields: str,)> CacheAccessor:

Build the CacheAccessor for this step's fluid_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's cache_filter_fields — empty for this step, whose rows are keyed by task_hash alone.

Returns A CacheAccessor scoped to this task_hash.

persist_fluid_metrics

def persist_fluid_metrics(    cache: CacheProtocol,    task_hash: str,    config: FluidCalculationConfig,    output: dict[str, FluidVolumeMetrics | str | None],    *,    project_id: str | None = None,    run_id: str | None = None,    filter_fields: tuple[str, ...] = (),)> FluidCalculationResult:

Upsert per-file fluid rows and return the cache-backed result.

Arguments

  • cache: The cache backend to persist into.
  • task_hash: Partition key for the fluid_calculation table.
  • config: The step config (passed through to the accessor).
  • output: Per-file result map — a FluidVolumeMetrics (success), a str (missing-data reason or calculation_error:...), or None.
  • project_id: Provenance only — not part of the cache key.
  • run_id: Optional provenance run ID.
  • filter_fields: The step's cache_filter_fields, forwarded to the accessor.

Returns FluidCalculationResult carrying the row count and a scoped accessor.