cleanup
This commit is contained in:
+11
-6
@@ -4,6 +4,7 @@ use crate::{api, core::config::Config, transport};
|
||||
use dashmap::DashMap;
|
||||
use rocket::routes;
|
||||
use sqlx::{SqlitePool, sqlite::SqliteConnectOptions};
|
||||
use state::AppState;
|
||||
use std::sync::Arc;
|
||||
|
||||
const DATABASE_PATH: &str = "server.db";
|
||||
@@ -31,12 +32,16 @@ pub async fn apply_schema(database: &SqlitePool) -> Result<(), sqlx::Error> {
|
||||
|
||||
pub fn build_rocket(database: SqlitePool) -> rocket::Rocket<rocket::Build> {
|
||||
rocket::build()
|
||||
.manage(state::AppState {
|
||||
database,
|
||||
registry: Arc::new(DashMap::new()),
|
||||
device_counts: Arc::new(DashMap::new()),
|
||||
config: Arc::new(Config::from_env()),
|
||||
})
|
||||
.manage(build_state(database))
|
||||
.mount("/", routes![transport::socket::connect, api::mcp::route])
|
||||
.register("/", rocket::catchers![api::catchers::default_catcher])
|
||||
}
|
||||
|
||||
fn build_state(database: SqlitePool) -> AppState {
|
||||
AppState {
|
||||
database,
|
||||
registry: Arc::new(DashMap::new()),
|
||||
device_counts: Arc::new(DashMap::new()),
|
||||
config: Arc::new(Config::from_env()),
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -9,6 +9,13 @@ pub type Database = SqlitePool;
|
||||
pub type DeviceCounts = DashMap<String, Arc<AtomicUsize>>;
|
||||
pub type Registry = DashMap<(String, String), RegistryEntry>;
|
||||
|
||||
pub struct AppState {
|
||||
pub database: Database,
|
||||
pub registry: Arc<Registry>,
|
||||
pub device_counts: Arc<DeviceCounts>,
|
||||
pub config: Arc<Config>,
|
||||
}
|
||||
|
||||
pub struct RegistryEntry {
|
||||
pub sender: mpsc::Sender<PendingExec>,
|
||||
pub in_flight: Arc<AtomicUsize>,
|
||||
@@ -26,10 +33,3 @@ pub struct PendingExec {
|
||||
pub command: String,
|
||||
pub reply: oneshot::Sender<ExecResult>,
|
||||
}
|
||||
|
||||
pub struct AppState {
|
||||
pub database: Database,
|
||||
pub registry: Arc<Registry>,
|
||||
pub device_counts: Arc<DeviceCounts>,
|
||||
pub config: Arc<Config>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user