rill_engine/
config.rs

1//! Configuration structs for the provider and tracers
2
3use rill_protocol::config::ConfigPatch;
4use rill_protocol::io::provider::{EntryId, StreamType};
5use serde::Deserialize;
6
7/// The external user app can set this value to override default server.
8/// If embedded server started it can put its socket address here.
9pub static NODE: ConfigPatch<String> = ConfigPatch::new("RR_NODE");
10
11/// The external user app can set this value to override the default name.
12pub static NAME: ConfigPatch<EntryId> = ConfigPatch::new("RR_NAME");
13
14/// Provider configuration
15#[derive(Deserialize, Debug, Clone)]
16pub struct EngineConfig {
17    // TODO: Use default serde value instead
18    /// Node where connect the provider
19    pub node: Option<String>,
20    // TODO: Use default serde value instead
21    /// The name of the provider
22    pub name: Option<EntryId>,
23    /// The type of the provider
24    pub provider_type: StreamType,
25}
26
27impl EngineConfig {
28    /// Creates a new `EngineConfig` of the specified type.
29    pub fn new(provider_type: StreamType) -> Self {
30        Self {
31            node: None,
32            name: None,
33            provider_type,
34        }
35    }
36}
37
38impl EngineConfig {
39    /// Returns `true` if node explicitly specified.
40    pub fn is_node_specified(&self) -> bool {
41        NODE.env_var().transpose().is_some() || self.node.is_some()
42    }
43
44    /// Full url of the node
45    pub fn node_url(&self) -> String {
46        let host = NODE.get(|| self.node.clone(), || "localhost:1636".into());
47        format!("ws://{}/live/provider", host)
48    }
49
50    /// Name of the provider
51    pub fn provider_name(&self) -> EntryId {
52        NAME.get(
53            || self.name.clone(),
54            || {
55                std::env::current_exe()
56                    .ok()
57                    .as_ref()
58                    .and_then(|path| path.as_path().file_name())
59                    .and_then(|path| path.to_str().map(EntryId::from))
60                    .unwrap_or_else(|| "rillrate".into())
61            },
62        )
63    }
64
65    /// The type of the provider
66    pub fn provider_type(&self) -> StreamType {
67        self.provider_type.clone()
68    }
69}