This commit is contained in:
2026-04-17 18:55:25 +02:00
commit d6a33a7fcb
16 changed files with 580 additions and 0 deletions

59
khbb_lib/src/app.rs Normal file
View File

@@ -0,0 +1,59 @@
// file: khbb_lib/src/app.rs
/// Runs the initial listener application workflow.
///
/// This first version only:
/// - loads configuration
/// - opens the SQLite connection pool
/// - verifies connectivity
/// - keeps the runtime alive as the future integration point for listener tasks
pub async fn run_listener_app(config_path: &str) -> core::result::Result<(), crate::KhbbError> {
let config_result = crate::KhbbAppConfig::load_from_json_file(config_path).await;
let config = match config_result {
Ok(value) => value,
Err(error) => {
return Err(error);
},
};
let tracing_result = crate::init_tracing(&config.log_filter);
match tracing_result {
Ok(()) => {},
Err(error) => {
return Err(error);
},
}
tracing::info!(
database_url = %config.database_url,
solana_http_rpc_url = %config.solana_http_rpc_url,
solana_ws_rpc_url = %config.solana_ws_rpc_url,
yellowstone_grpc_url = ?config.yellowstone_grpc_url,
"khbb listener app starting"
);
let connect_result = sqlx::sqlite::SqlitePoolOptions::new()
.max_connections(1)
.connect(&config.database_url)
.await;
let pool = match connect_result {
Ok(value) => value,
Err(error) => {
return Err(crate::KhbbError::Database {
context: "connect sqlite pool",
message: error.to_string(),
});
},
};
let ping_result = sqlx::query("SELECT 1;").execute(&pool).await;
match ping_result {
Ok(_) => {
tracing::info!("sqlite connectivity check succeeded");
},
Err(error) => {
return Err(crate::KhbbError::Database {
context: "ping sqlite database",
message: error.to_string(),
});
},
}
tracing::info!("listener tasks are not wired yet");
Ok(())
}