@@ -172,18 +172,48 @@ async fn get_job_by_id(id: web::Path<String>, ctx: web::Data<Context>) -> Result
172172 Ok ( res)
173173}
174174
175- #[ get( "/jobs/{name }/log" ) ]
175+ #[ get( "/jobs/{id }/log" ) ]
176176async fn get_job_log_by_name (
177- name : web:: Path < String > ,
177+ id : web:: Path < String > ,
178178 ctx : web:: Data < Context > ,
179179) -> Result < HttpResponse > {
180- let log_dir = shellexpand:: tilde ( & ctx. logs_dir ) . into_owned ( ) ;
181- let log_file_name = format ! ( "{}/{}.log" , & log_dir, name) ;
180+ let query = database:: Query {
181+ query : job:: query:: GET_JOB_BY_ID . to_owned ( ) ,
182+ params : vec ! [ id. to_string( ) ] ,
183+ map_result : |row| {
184+ let commands: serde_json:: Value = row. get ( 4 ) ?;
185+ Ok ( job:: Job {
186+ commands,
187+ id : row. get ( 0 ) ?,
188+ name : row. get ( 1 ) ?,
189+ status : row. get ( 2 ) ?,
190+ project : row. get ( 3 ) ?,
191+ started_at : row. get ( 5 ) ?,
192+ ended_at : row. get ( 6 ) ?,
193+ } )
194+ } ,
195+ } ;
182196
183- let log = tokio:: fs:: read_to_string ( log_file_name) . await ?;
184- let res = HttpResponse :: Ok ( ) . body ( log) ;
197+ let job = ctx
198+ . database
199+ . send ( query)
200+ . await
201+ . map_err ( |err| SubiloError :: DatabaseActor { source : err } ) ?
202+ . map_err ( |err| SubiloError :: DatabaseQuery { source : err } ) ?;
185203
186- Ok ( res)
204+ match job. first ( ) {
205+ Some ( job) => {
206+ let log_dir = shellexpand:: tilde ( & ctx. logs_dir ) . into_owned ( ) ;
207+ let log_file_name = format ! ( "{}/{}.log" , & log_dir, job. name) ;
208+
209+ let log = tokio:: fs:: read_to_string ( log_file_name) . await ?;
210+
211+ let res = HttpResponse :: Ok ( ) . body ( log) ;
212+
213+ Ok ( res)
214+ }
215+ None => Ok ( HttpResponse :: NotFound ( ) . body ( "Not Found" ) ) ,
216+ }
187217}
188218
189219#[ actix_rt:: main]
0 commit comments