Skip to main content

agent_exec/
status.rs

1//! Implementation of the `status` sub-command.
2
3use anyhow::Result;
4use tracing::debug;
5
6use crate::jobstore::{JobDir, resolve_root};
7use crate::schema::{Response, StatusData};
8
9/// Options for the `status` sub-command.
10#[derive(Debug)]
11pub struct StatusOpts<'a> {
12    pub job_id: &'a str,
13    pub root: Option<&'a str>,
14}
15
16/// Execute `status`: read job state and emit JSON.
17pub fn execute(opts: StatusOpts) -> Result<()> {
18    let root = resolve_root(opts.root);
19    let job_dir = JobDir::open(&root, opts.job_id)?;
20
21    let meta = job_dir.read_meta()?;
22    let state = job_dir.read_state()?;
23
24    debug!(job_id = %opts.job_id, state = ?state.status(), "status query");
25
26    let response = Response::new(
27        "status",
28        StatusData {
29            job_id: job_dir.job_id.clone(),
30            state: state.status().as_str().to_string(),
31            exit_code: state.exit_code(),
32            created_at: meta.created_at,
33            started_at: state.started_at().map(|s| s.to_string()),
34            finished_at: state.finished_at,
35        },
36    );
37    response.print();
38    Ok(())
39}