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 reuses file_metadata's persisted file
inventory instead of walking the directory, and does nothing if that
inventory is absent (it never walks). A success full file_metadata
pass submits it (bitfount.runtimes.metadata_convergence).
The body runs under metadata:<task_hash>, shared with
file_metadata_runtime, and fences its row writes on it. Holding the lock,
it scans only over a current inventory: the latest full index pass is
success, finished before this run acquired the lock, and no index run is
pending. Otherwise it skips with stop_reason="inventory_not_current"; the
pending or re-run index submits the next scan when it succeeds. A run
that waits longer than metadata_lock_wait_seconds for the lock skips with
stop_reason="metadata_busy" and submits nothing.
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.
Progress events
A scan run reports the scan step of the preprocessing pass named by its
preprocessing_id parameter, which the file_metadata run that submits it
passes on, continuing that pass's sequence: see
MetadataRun.continue_file_metadata_pass. A scan with no id, such as a
standalone run, reports nothing. It joins the pass only once it is about to
scan, so a run that skips over an inventory that is not current reports
nothing, and the run that does the work reports for it.
SCAN_METADATA_STARTED goes out once the files to look at are known, then
SCAN_METADATA_COMPLETED when the scan finishes, or ERROR when it fails or
ends partial. A partial scan's follow-up finds the pass ended and reports
nothing. A non-ophthalmology datasource has no scans, so its run reports the
step started and completed with nothing to do, and the pass still reads as
finished. Consumers infer a dataset is ready from
FILE_METADATA_COMPLETED and SCAN_METADATA_COMPLETED under one pass, so
SCAN_METADATA_COMPLETED is never sent for a scan that did not finish.
Run-state tracking and config-error handling follow file_metadata_runtime
exactly — see that module for the rationale. There is no completion callback:
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, preprocessing_id: str | None = None,) ‑> int:Collect and persist per-scan metadata for one ophthalmology datasource.
Arguments
pod_name: Name of the pod (used to derivetask_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'sbackground_cache.dbSQLite file.path: Directory the datasource walks (required for ophthalmology sources).datasource_kwargs: Extra constructor kwargs for the datasource (e.g.HeidelbergE2ESourceneedslateralityandseries_protocol).only_paths: When set, extract scans for these inventory paths only. 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.preprocessing_id: The preprocessing pass whose scan step this run reports, passed on from thefile_metadatarun before it. Without it the run reports no progress events.
Returns
The number of ScanMetadata rows written.