Skip to main content

bbox_processes_server/
config.rs

1use bbox_core::config::{config_error_exit, ConfigError};
2use bbox_core::service::ServiceConfig;
3use clap::ArgMatches;
4use serde::Deserialize;
5
6#[derive(Deserialize, Default, Debug)]
7#[serde(default, deny_unknown_fields)]
8pub struct ProcessesServiceCfg {
9    pub dagster_backend: Option<DagsterBackendCfg>,
10}
11
12/// Dagster backend configuration
13#[derive(Deserialize, Clone, Debug)]
14#[serde(deny_unknown_fields)]
15pub struct DagsterBackendCfg {
16    /// GraphQL URL (e.g. `http://localhost:3000/graphql`)
17    pub graphql_url: String,
18    /// Dagster repository (e.g. `fpds2_processing_repository`)
19    pub repository_name: String,
20    /// Dagster repository location (e.g. `fpds2_processing.repos`)
21    pub repository_location_name: String,
22    /// Backend request timeout (ms) (Default: 10s)
23    pub request_timeout: Option<u64>,
24}
25
26impl ServiceConfig for ProcessesServiceCfg {
27    fn initialize(_cli: &ArgMatches) -> Result<Self, ConfigError> {
28        let cfg = ProcessesServiceCfg::from_config();
29        Ok(cfg)
30    }
31}
32
33impl ProcessesServiceCfg {
34    pub fn from_config() -> Self {
35        let config = bbox_core::config::app_config();
36        if config.find_value("processes").is_ok() {
37            let cfg: Self = config
38                .extract_inner("processes")
39                .map_err(config_error_exit)
40                .unwrap();
41            if !cfg.has_backend() {
42                config_error_exit("Processing backend configuration missing");
43            }
44            cfg
45        } else {
46            Default::default()
47        }
48    }
49    pub fn has_backend(&self) -> bool {
50        self.dagster_backend.is_some()
51    }
52}