use super::Running;
use crate::Result;
use crate::error::Error;
use crate::executor::{Cx, run_steps};
use crate::store::RunRecord;
const SEALED: &str = "true";
impl Running<'_> {
pub(crate) async fn seal(&self, cx: &mut Cx<'_>, record: &mut RunRecord) -> Result<()> {
let Some(seal) = self.manifest().lifecycle.seal.as_ref() else {
return Ok(());
};
let param = seal.param.to_string();
let mut params = cx.vars.params().clone();
params.insert(param.clone(), SEALED.to_owned());
cx.vars.set_params(params);
record.params.insert(param, SEALED.to_owned());
self.runner.store.save(record)?;
let sealed = run_steps(cx, "lifecycle.seal", seal.steps.as_slice()).await;
sealed.map(drop).map_err(|e| Error::Unsealed {
run: self.name().to_string(),
reason: e.to_string(),
})
}
pub(crate) fn forget_seal(&self) -> Result<()> {
let Some(seal) = self.manifest().lifecycle.seal.as_ref() else {
return Ok(());
};
let Some(mut record) = self.runner.store.record(self.name())? else {
return Ok(());
};
if record.params.remove(seal.param.as_str()).is_some() {
self.runner.store.save(&record)?;
}
Ok(())
}
}