Skip to main content

objectiveai_cli/command/api/
kill.rs

1//! `api kill --global` — terminate the api server by killing the
2//! owner(s) of its machine-wide lock at `<dir>/bin/locks` key
3//! `api`. Idempotent: a count of zero is not an error. There is
4//! exactly one api lock, so no concurrency is needed.
5
6use objectiveai_sdk::cli::command::api::kill::{Request, Response};
7
8use crate::command::kill_helpers::kill_lock_owners;
9use crate::context::Context;
10use crate::error::Error;
11
12pub async fn execute(ctx: &Context, _request: Request) -> Result<Response, Error> {
13    // The SDK `TryFrom` already enforced --global.
14    let locks_dir = ctx.filesystem.bin_dir().join("locks");
15    let killed = kill_lock_owners(locks_dir, "api").await?;
16    Ok(Response { killed })
17}
18
19pub mod request_schema {
20    use objectiveai_sdk::cli::command::api::kill as sdk;
21    use objectiveai_sdk::cli::command::api::kill::request_schema::{Request, Response};
22
23    use crate::context::Context;
24    use crate::error::Error;
25
26    pub async fn execute(_ctx: &Context, _request: Request) -> Result<Response, Error> {
27        Ok(objectiveai_sdk::cli::command::ResponseSchema(schemars::schema_for!(sdk::Request)))
28    }
29}
30
31pub mod response_schema {
32    use objectiveai_sdk::cli::command::api::kill as sdk;
33    use objectiveai_sdk::cli::command::api::kill::response_schema::{Request, Response};
34
35    use crate::context::Context;
36    use crate::error::Error;
37
38    pub async fn execute(_ctx: &Context, _request: Request) -> Result<Response, Error> {
39        Ok(objectiveai_sdk::cli::command::ResponseSchema(schemars::schema_for!(sdk::Response)))
40    }
41}