1use anyhow::Result;
4use tracing::debug;
5
6use crate::jobstore::{JobDir, resolve_root};
7use crate::schema::{Response, StatusData};
8
9#[derive(Debug)]
11pub struct StatusOpts<'a> {
12 pub job_id: &'a str,
13 pub root: Option<&'a str>,
14}
15
16pub 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: opts.job_id.to_string(),
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}