scientific-workflow 0.18.0

Configuration-driven scientific tasks, typed state, and durable recordings
Documentation
//! Rebuildable run index. Authoritative manifests remain the source of truth.
use crate::{
    artifact::{RunManifest, StorageLocation},
    storage::Store,
};
use serde::{Deserialize, Serialize};
use std::{io, path::Path};
/// A searchable run summary, with outcome separate from retention and liveness.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RunRecord {
    /// UTC operational identity.
    pub run_id: String,
    /// StudyPlan or campaign.
    pub kind: String,
    /// Last recorded lifecycle outcome; does not establish current liveness.
    pub outcome: crate::protocol::Outcome,
    /// Scientific input fingerprint.
    pub scientific_identity: String,
    /// Whether raw artifacts have intentionally been removed.
    pub sealed: bool,
    /// Capture closure was committed before execution.
    pub capture_complete: bool,
}
impl From<&RunManifest> for RunRecord {
    fn from(m: &RunManifest) -> Self {
        Self {
            run_id: m.run_id.clone(),
            kind: m.kind.clone(),
            outcome: m.outcome,
            scientific_identity: m.scientific_identity.clone(),
            sealed: !m.removed.is_empty(),
            capture_complete: m.capture_complete,
        }
    }
}
pub(crate) fn index_manifest(
    store: &Store,
    manifest: &RunManifest,
    workspace: &Path,
) -> io::Result<()> {
    let mut record = RunRecord::from(manifest);
    record.sealed = store
        .json::<crate::seal::SealReport>(&format!("{}/seal.json", manifest.run_id))
        .is_ok();
    store.put_json(
        &format!("registry/{}.json", manifest.run_id),
        &record,
        workspace,
        false,
    )
}
/// Queries the derived index. Use `open_run` to verify selected authoritative data.
pub fn query(location: &StorageLocation) -> io::Result<Vec<RunRecord>> {
    let store = Store::open(location)?;
    let mut out = Vec::new();
    for key in store.backend.list("registry/")? {
        out.push(store.json(&key)?);
    }
    out.sort_by(|a: &RunRecord, b| a.run_id.cmp(&b.run_id));
    Ok(out)
}
/// Rebuilds the index by reading authoritative run manifests, without executing science.
pub fn rebuild(location: &StorageLocation, workspace: &Path) -> io::Result<Vec<RunRecord>> {
    let store = Store::open(location)?;
    let mut out = Vec::new();
    for key in store.backend.list("")? {
        if key.ends_with("/manifest.json") && key.split('/').count() == 2 {
            let manifest: RunManifest = store.json(&key)?;
            if manifest.format != "scientific-workflow-run.v1" {
                continue;
            }
            index_manifest(&store, &manifest, workspace)?;
            out.push(store.json(&format!("registry/{}.json", manifest.run_id))?);
        }
    }
    Ok(out)
}