use crate::{commands::EntryPoint, config::RusticSchedulerConfig};
use abscissa_core::{
application::{self, AppCell},
config::{self, CfgCell},
trace, Application, FrameworkError, StandardPaths,
};
use abscissa_tokio::TokioComponent;
pub static RUSTIC_SCHEDULER_APP: AppCell<RusticSchedulerApp> = AppCell::new();
#[derive(Debug)]
pub struct RusticSchedulerApp {
config: CfgCell<RusticSchedulerConfig>,
state: application::State<Self>,
}
impl Default for RusticSchedulerApp {
fn default() -> Self {
Self {
config: CfgCell::default(),
state: application::State::default(),
}
}
}
impl Application for RusticSchedulerApp {
type Cmd = EntryPoint;
type Cfg = RusticSchedulerConfig;
type Paths = StandardPaths;
fn config(&self) -> config::Reader<RusticSchedulerConfig> {
self.config.read()
}
fn state(&self) -> &application::State<Self> {
&self.state
}
fn register_components(&mut self, command: &Self::Cmd) -> Result<(), FrameworkError> {
let mut components = self.framework_components(command)?;
components.push(Box::new(TokioComponent::new()?));
self.state.components_mut().register(components)
}
fn after_config(&mut self, config: Self::Cfg) -> Result<(), FrameworkError> {
let mut components = self.state.components_mut();
components.after_config(&config)?;
self.config.set_once(config);
Ok(())
}
fn tracing_config(&self, command: &EntryPoint) -> trace::Config {
if command.verbose {
trace::Config::verbose()
} else {
trace::Config::default()
}
}
}