41 lines
1.3 KiB
Rust
41 lines
1.3 KiB
Rust
use std::sync::{Arc, Mutex};
|
|
|
|
use config::SharedAppConfig;
|
|
use sonic_channel::SonicChannel;
|
|
|
|
#[derive(Clone)]
|
|
pub struct Context {
|
|
pub search: Arc<Mutex<sonic_channel::SearchChannel>>,
|
|
pub ingest: Arc<Mutex<sonic_channel::IngestChannel>>,
|
|
}
|
|
|
|
impl Context {
|
|
pub fn new(config: SharedAppConfig) -> Option<Self> {
|
|
let enabled = config.lock().search().search_active();
|
|
if enabled {
|
|
let search = {
|
|
let l = config.lock();
|
|
sonic_channel::SearchChannel::start(
|
|
l.search().sonic_search_addr(),
|
|
l.search().sonic_search_pass(),
|
|
)
|
|
.unwrap_or_else(|e| panic!("Failed to connect to sonic search channel. {}", e))
|
|
};
|
|
let ingest = {
|
|
let l = config.lock();
|
|
sonic_channel::IngestChannel::start(
|
|
l.search().sonic_ingest_addr(),
|
|
l.search().sonic_ingest_pass(),
|
|
)
|
|
.unwrap_or_else(|e| panic!("Failed to connect to sonic ingest channel. {}", e))
|
|
};
|
|
Some(Self {
|
|
search: Arc::new(Mutex::new(search)),
|
|
ingest: Arc::new(Mutex::new(ingest)),
|
|
})
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
}
|