1#![warn(missing_docs)]
4#![forbid(unsafe_code)]
5
6use std::path::PathBuf;
7
8use crate::config::load_config;
9use crate::error::IndexerError;
10use crate::indexer::start_indexer;
11use tracing::{error, info};
12
13pub mod cli;
14pub mod config;
15pub mod error;
16pub mod indexer;
17#[cfg(feature = "prometheus")]
18pub mod metrics;
19
20pub async fn run(config_path: PathBuf) -> Result<(), IndexerError> {
26 zaino_common::logging::try_init();
27
28 info!(version = env!("CARGO_PKG_VERSION"), "zainod started");
29 let config = load_config(&config_path)?;
30
31 #[cfg(feature = "prometheus")]
32 if let Some(endpoint) = config.metrics_endpoint {
33 crate::metrics::init(endpoint)?;
34 }
35
36 loop {
37 match start_indexer(config.clone()).await {
38 Ok(joinhandle_result) => {
39 info!("Zaino Indexer started successfully.");
40 match joinhandle_result.await {
41 Ok(indexer_result) => match indexer_result {
42 Ok(()) => {
43 info!("Exiting Zaino successfully.");
44 return Ok(());
45 }
46 Err(IndexerError::Restart) => {
47 error!("Zaino encountered critical error, restarting.");
48 continue;
49 }
50 Err(e) => {
51 error!(%e, "exiting Zaino with error");
52 return Err(e);
53 }
54 },
55 Err(e) => {
56 error!(%e, "Zaino exited early with error");
57 return Err(e.into());
58 }
59 }
60 }
61 Err(e) => {
62 error!(%e, "Zaino failed to start");
63 return Err(e);
64 }
65 }
66 }
67}