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
18pub async fn run(config_path: PathBuf) -> Result<(), IndexerError> {
24 zaino_common::logging::try_init();
25
26 info!("zainod v{}", env!("CARGO_PKG_VERSION"));
27 let config = load_config(&config_path)?;
28
29 loop {
30 match start_indexer(config.clone()).await {
31 Ok(joinhandle_result) => {
32 info!("Zaino Indexer started successfully.");
33 match joinhandle_result.await {
34 Ok(indexer_result) => match indexer_result {
35 Ok(()) => {
36 info!("Exiting Zaino successfully.");
37 return Ok(());
38 }
39 Err(IndexerError::Restart) => {
40 error!("Zaino encountered critical error, restarting.");
41 continue;
42 }
43 Err(e) => {
44 error!("Exiting Zaino with error: {}", e);
45 return Err(e);
46 }
47 },
48 Err(e) => {
49 error!("Zaino exited early with error: {}", e);
50 return Err(e.into());
51 }
52 }
53 }
54 Err(e) => {
55 error!("Zaino failed to start with error: {}", e);
56 return Err(e);
57 }
58 }
59 }
60}