@@ -118,13 +118,45 @@ async fn cmd_go(
118118 }
119119
120120 let run: RunResponse = resp. json ( ) . await ?;
121- println ! ( "Job submitted successfully!" ) ;
122- println ! ( " ID: {}" , run. id) ;
123- println ! ( "\n Check the result with:\n cloude status {}" , run. id) ;
124- Ok ( ( ) )
121+ let job_id = run. id . clone ( ) ;
122+
123+ loop {
124+ tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
125+
126+ let status_url = format ! ( "{backend}/status/{job_id}" ) ;
127+ let status_resp = client. get ( & status_url) . send ( ) . await ?;
128+
129+ if !status_resp. status ( ) . is_success ( ) {
130+ let status = status_resp. status ( ) ;
131+ let err: ErrorBody = status_resp. json ( ) . await . unwrap_or ( ErrorBody {
132+ error : format ! ( "HTTP {status}" ) ,
133+ } ) ;
134+ return Err ( format ! ( "Backend error (HTTP {status}): {}" , err. error) . into ( ) ) ;
135+ }
136+
137+ let st: StatusResponse = status_resp. json ( ) . await ?;
138+
139+ if st. status == "done" || st. status == "error" {
140+ println ! ( "Status: {}" , st. status) ;
141+ if let Some ( code) = st. exit_code {
142+ println ! ( "Exit code: {code}" ) ;
143+ }
144+ if let Some ( ref out) = st. stdout {
145+ if !out. is_empty ( ) {
146+ println ! ( "{out}" ) ;
147+ }
148+ }
149+ if let Some ( ref err) = st. stderr {
150+ if !err. is_empty ( ) {
151+ println ! ( "{err}" ) ;
152+ }
153+ }
154+ return Ok ( ( ) ) ;
155+ }
156+ }
125157}
126158
127- // ── status: poll job result ─ ────────────────────────────────────────
159+ // ── status: query job result ────────────────────────────────────────
128160
129161async fn cmd_status (
130162 client : & reqwest:: Client ,
@@ -144,21 +176,10 @@ async fn cmd_status(
144176
145177 let st: StatusResponse = resp. json ( ) . await ?;
146178
147- println ! ( "Job {}" , st. id) ;
148- println ! ( " Status: {}" , st. status) ;
149-
179+ println ! ( "Job ID: {}" , st. id) ;
180+ println ! ( "Status: {}" , st. status) ;
150181 if let Some ( code) = st. exit_code {
151- println ! ( " Exit code: {code}" ) ;
152- }
153- if let Some ( ref out) = st. stdout {
154- if !out. is_empty ( ) {
155- println ! ( " ── stdout ──\n {out}" ) ;
156- }
157- }
158- if let Some ( ref err) = st. stderr {
159- if !err. is_empty ( ) {
160- println ! ( " ── stderr ──\n {err}" ) ;
161- }
182+ println ! ( "Exit code: {code}" ) ;
162183 }
163184 Ok ( ( ) )
164185}
0 commit comments