36 lines
846 B
Rust
36 lines
846 B
Rust
use crate::core::config::Config;
|
|
use dashmap::DashMap;
|
|
use serde::Serialize;
|
|
use sqlx::SqlitePool;
|
|
use std::sync::{Arc, atomic::AtomicUsize};
|
|
use tokio::sync::{mpsc, oneshot};
|
|
|
|
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>,
|
|
}
|
|
|
|
#[derive(Debug, Serialize)]
|
|
pub struct ExecResult {
|
|
pub exit_code: i32,
|
|
pub stdout: String,
|
|
pub stderr: String,
|
|
}
|
|
|
|
pub struct PendingExec {
|
|
pub exec_id: String,
|
|
pub command: String,
|
|
pub reply: oneshot::Sender<ExecResult>,
|
|
}
|