49 lines
1.2 KiB
Rust
49 lines
1.2 KiB
Rust
use redis::aio::ConnectionManager;
|
|
use cave::config::LoadConfig;
|
|
use crate::request_mux::{Muxable, RequestMux};
|
|
|
|
mod config;
|
|
mod tag;
|
|
mod trends;
|
|
mod html_template;
|
|
mod http_server;
|
|
mod request_mux;
|
|
|
|
#[derive(Clone)]
|
|
pub struct RequestFactory {
|
|
redis_man: ConnectionManager,
|
|
}
|
|
|
|
#[axum::async_trait]
|
|
impl Muxable for RequestFactory {
|
|
type Key = Option<String>;
|
|
type Result = crate::trends::TrendsResults;
|
|
|
|
async fn request(&self, language: Self::Key) -> Self::Result {
|
|
let mut redis_man = self.redis_man.clone();
|
|
trends::TrendAnalyzer::run(&mut redis_man, 20, &[4, 24, 24 * 7], language)
|
|
.await
|
|
.unwrap()
|
|
}
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
cave::init::exit_on_panic();
|
|
cave::init::init_logger();
|
|
|
|
let config = config::Config::load();
|
|
|
|
cave::systemd::status("Starting redis client");
|
|
|
|
let redis_client = redis::Client::open(config.redis)
|
|
.expect("redis::Client");
|
|
let redis_man = redis::aio::ConnectionManager::new(redis_client).await
|
|
.expect("redis::aio::ConnectionManager");
|
|
let mux = RequestMux::new(RequestFactory {
|
|
redis_man,
|
|
});
|
|
|
|
http_server::start(config.listen_port, mux).await;
|
|
}
|