use bbox_core::config::{config_error_exit, ConfigError};
use bbox_core::service::ServiceConfig;
use clap::ArgMatches;
use serde::Deserialize;
#[derive(Deserialize, Default, Debug)]
#[serde(default, deny_unknown_fields)]
pub struct ProcessesServiceCfg {
pub dagster_backend: Option<DagsterBackendCfg>,
}
#[derive(Deserialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct DagsterBackendCfg {
pub graphql_url: String,
pub repository_name: String,
pub repository_location_name: String,
pub request_timeout: Option<u64>,
}
impl ServiceConfig for ProcessesServiceCfg {
fn initialize(_cli: &ArgMatches) -> Result<Self, ConfigError> {
let cfg = ProcessesServiceCfg::from_config();
Ok(cfg)
}
}
impl ProcessesServiceCfg {
pub fn from_config() -> Self {
let config = bbox_core::config::app_config();
if config.find_value("processes").is_ok() {
let cfg: Self = config
.extract_inner("processes")
.map_err(config_error_exit)
.unwrap();
if !cfg.has_backend() {
config_error_exit("Processing backend configuration missing");
}
cfg
} else {
Default::default()
}
}
pub fn has_backend(&self) -> bool {
self.dagster_backend.is_some()
}
}