rust/ingestor/src/main.rs
1 mod clickhouse;
2 mod config;
3 mod ingestor;
4 mod model;
5 mod normalize;
6
7 use crate::config::load_config;
8 use crate::ingestor::run_ingestor;
9 use anyhow::{Context, Result};
10 use std::path::PathBuf;
11 use tracing_subscriber::EnvFilter;
12
13 fn parse_config_path() -> PathBuf {
14 let mut args = std::env::args().skip(1);
15 let mut config_path = default_config_path();
16
17 while let Some(arg) = args.next() {
18 if arg == "--config" {
19 if let Some(value) = args.next() {
20 config_path = PathBuf::from(value);
21 }
22 }
23 }
24
25 config_path
26 }
27
28 fn default_config_path() -> PathBuf {
29 if let Some(home) = std::env::var_os("HOME") {
30 let path = PathBuf::from(home).join(".moraine").join("config.toml");
31 if path.exists() {
32 return path;
33 }
34 }
35
36 PathBuf::from("config/moraine.toml")
37 }
38
39 #[tokio::main(flavor = "multi_thread")]
40 async fn main() -> Result<()> {
41 tracing_subscriber::fmt()
42 .with_env_filter(
43 EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
44 )
45 .with_target(false)
46 .init();
47
48 let config_path = parse_config_path();
49 let config = load_config(&config_path)
50 .with_context(|| format!("failed to load config {}", config_path.display()))?;
51
52 run_ingestor(config).await
53 }