use std::time::Duration;
use frame_core::runtime::RuntimePolicy;
use crate::application::run_application;
use crate::cli::Cli;
use crate::config::FrameConfig;
use crate::error::HostError;
use crate::manifest;
use crate::spec::{AppError, AppSpec, ComponentInstall};
const SCHEDULER_THREADS: usize = 2;
const OPERATION_TIMEOUT: Duration = Duration::from_secs(3);
pub fn run(cli: &Cli) -> Result<(), HostError> {
let config = FrameConfig::load(&cli.config)?;
run_application(&config, bundled_spec())
}
fn bundled_spec() -> AppSpec {
AppSpec {
components: vec![ComponentInstall {
meta: manifest::component_meta(),
bytecode: manifest::PRESENCE_BYTECODE.to_vec(),
support_modules: Vec::new(),
}],
policy: RuntimePolicy {
scheduler_threads: SCHEDULER_THREADS,
operation_timeout: OPERATION_TIMEOUT,
},
readiness: Box::new(|registry| {
let answer = registry
.probe_child(manifest::component_id(), manifest::PRESENCE_CHILD)
.map_err(|error| AppError::new(format!("liveness probe failed: {error}")))?;
if answer == manifest::LIVENESS_MESSAGE {
Ok(())
} else {
Err(AppError::new(format!(
"presence child answered liveness probe with {answer}, expected {}",
manifest::LIVENESS_MESSAGE
)))
}
}),
announce: Box::new(|registry, announcer| {
let answer = registry
.probe_child(manifest::component_id(), manifest::PRESENCE_CHILD)
.map_err(|error| AppError::new(format!("announce-time probe failed: {error}")))?;
announcer
.announce_fact(serde_json::json!({
"componentId": manifest::component_id().to_string(),
"contract": manifest::CONTRACT_ID,
"presenceProbe": answer,
}))
.map_err(|error| AppError::new(format!("fact announcement refused: {error}")))
}),
}
}