Skip to main content

flow

Prefect flow for the scan_metadata runtime.

Entrypoint

scan_metadata_runtime Top-level flow — collect and persist per-scan header metadata for a single ophthalmology datasource. It is chained after file_metadata_runtime: both the orchestrator and run_pod submit it via run_deployment("background/scan_metadata_runtime", …) right after their file_metadata submission for the datasource completes. It reuses file_metadata's persisted file inventory instead of walking the directory, and does nothing if that inventory is absent (it never walks).

Because the inventory is the input, the flow refuses to start while a file_metadata run for the same (pod, datasource) is still building it — see _must_stand_down. That is not merely defensive: four different submission paths can produce the overlap, and a scan that runs anyway finishes COMPLETED over a partial inventory, which is under-coverage nothing later notices. Standing down is safe only because something runs scan afterwards, so when the chain automation is absent this run schedules its own replacement rather than dropping the work (_defer_until_indexing_finishes).

Datasource routing

Only ophthalmology datasources produce per-scan header metadata, so the flow resolves the datasource_type and skips anything that is not an _OphthalmologySource subclass (a no-op success, not a failure). Ophthalmology sources are all FileSystemIterableSources that require a directory path.

Run-state tracking and config-error handling follow file_metadata_runtime exactly — see that module for the rationale. There is no completion callback: scan_metadata is submitted by a server-side Prefect automation (the orchestrator chain) and by run_pod, neither of which passes a callback URL — the desktop app is notified off the file_metadata run instead.

Module

Functions

scan_metadata_runtime

def scan_metadata_runtime(    pod_name: str,    datasource_name: str,    datasource_type: str,    cache_db_path: str,    path: str | None = None,    datasource_kwargs: dict[str, Any] | None = None,    only_paths: list[str] | None = None,)> int:

Collect and persist per-scan metadata for one ophthalmology datasource.

Arguments

  • pod_name: Name of the pod (used to derive task_hash).
  • datasource_name: Name of the datasource within the pod.
  • datasource_type: Datasource type string from the pod config.
  • cache_db_path: Path to the pod's background_cache.db SQLite file.
  • path: Directory the datasource walks (required for ophthalmology sources).
  • datasource_kwargs: Extra constructor kwargs for the datasource (e.g. HeidelbergE2ESource needs laterality and series_protocol).
  • only_paths: When set, extract scans for these inventory paths only. Forwarded by the file-metadata chain automation so a scoped index run produces a scoped extraction run. May name directories as well as files; any spelling is accepted, since each path is normalized before being looked up. A path with no inventory row is simply absent from the scope.

Returns The number of ScanMetadata rows written.