Skip to main content

sqlite_graphrag/commands/
daemon.rs

1use crate::constants::DAEMON_IDLE_SHUTDOWN_SECS;
2use crate::errors::AppError;
3use crate::output;
4use crate::paths::AppPaths;
5
6#[derive(clap::Args)]
7pub struct DaemonArgs {
8    #[arg(long, default_value_t = DAEMON_IDLE_SHUTDOWN_SECS)]
9    pub idle_shutdown_secs: u64,
10    #[arg(long)]
11    pub ping: bool,
12    #[arg(long)]
13    pub stop: bool,
14}
15
16pub fn run(args: DaemonArgs) -> Result<(), AppError> {
17    let paths = AppPaths::resolve(None)?;
18    paths.ensure_dirs()?;
19
20    if args.ping {
21        let response = crate::daemon::try_ping(&paths.models)?
22            .ok_or_else(|| AppError::NotFound("daemon not running".to_string()))?;
23        output::emit_json(&response)?;
24        return Ok(());
25    }
26
27    if args.stop {
28        let response = crate::daemon::try_shutdown(&paths.models)?
29            .ok_or_else(|| AppError::NotFound("daemon not running".to_string()))?;
30        output::emit_json(&response)?;
31        return Ok(());
32    }
33
34    crate::daemon::run(&paths.models, args.idle_shutdown_secs)
35}