scientific_workflow/
registry.rs1use crate::{
3 artifact::{RunManifest, StorageLocation},
4 storage::Store,
5};
6use serde::{Deserialize, Serialize};
7use std::{io, path::Path};
8#[derive(Clone, Debug, Serialize, Deserialize)]
10pub struct RunRecord {
11 pub run_id: String,
13 pub kind: String,
15 pub outcome: scientific_workflow_protocol::Outcome,
17 pub scientific_identity: String,
19 pub sealed: bool,
21 pub capture_complete: bool,
23}
24impl From<&RunManifest> for RunRecord {
25 fn from(m: &RunManifest) -> Self {
26 Self {
27 run_id: m.run_id.clone(),
28 kind: m.kind.clone(),
29 outcome: m.outcome,
30 scientific_identity: m.scientific_identity.clone(),
31 sealed: !m.removed.is_empty(),
32 capture_complete: m.capture_complete,
33 }
34 }
35}
36pub(crate) fn index_manifest(
37 store: &Store,
38 manifest: &RunManifest,
39 workspace: &Path,
40) -> io::Result<()> {
41 let mut record = RunRecord::from(manifest);
42 record.sealed = store
43 .json::<crate::seal::SealReport>(&format!("{}/seal.json", manifest.run_id))
44 .is_ok();
45 store.put_json(
46 &format!("registry/{}.json", manifest.run_id),
47 &record,
48 workspace,
49 false,
50 )
51}
52pub fn query(location: &StorageLocation) -> io::Result<Vec<RunRecord>> {
54 let store = Store::open(location)?;
55 let mut out = Vec::new();
56 for key in store.backend.list("registry/")? {
57 out.push(store.json(&key)?);
58 }
59 out.sort_by(|a: &RunRecord, b| a.run_id.cmp(&b.run_id));
60 Ok(out)
61}
62pub fn rebuild(location: &StorageLocation, workspace: &Path) -> io::Result<Vec<RunRecord>> {
64 let store = Store::open(location)?;
65 let mut out = Vec::new();
66 for key in store.backend.list("")? {
67 if key.ends_with("/manifest.json") && key.split('/').count() == 2 {
68 let manifest: RunManifest = store.json(&key)?;
69 if manifest.format != "scientific-workflow-run.v1" {
70 continue;
71 }
72 index_manifest(&store, &manifest, workspace)?;
73 out.push(store.json(&format!("registry/{}.json", manifest.run_id))?);
74 }
75 }
76 Ok(out)
77}