@@ -37,8 +37,6 @@ pub struct ListArgs {
3737 /// Sort by field (memory, cpu)
3838 #[ clap( long, value_name = "FIELD" ) ]
3939 pub sort_by : Option < String > ,
40- #[ clap( long) ]
41- pub clean : bool ,
4240}
4341
4442impl Executable for ListArgs {
@@ -49,26 +47,18 @@ impl Executable for ListArgs {
4947 . await
5048 . wrap_err ( "failed to connect to dora coordinator" ) ?;
5149
52- list (
53- & client,
54- self . format ,
55- self . status ,
56- self . name ,
57- self . sort_by ,
58- self . clean ,
59- )
60- . await
50+ list ( & client, self . format , self . status , self . name , self . sort_by ) . await
6151 }
6252}
6353
6454#[ derive( Serialize ) ]
65- struct OutputEntry {
66- uuid : Uuid ,
67- name : String ,
68- status : DataflowStatus ,
69- nodes : usize ,
70- cpu : f64 ,
71- memory : f64 ,
55+ pub ( super ) struct OutputEntry {
56+ pub uuid : Uuid ,
57+ pub name : String ,
58+ pub status : DataflowStatus ,
59+ pub nodes : usize ,
60+ pub cpu : f64 ,
61+ pub memory : f64 ,
7262}
7363
7464#[ derive( Default ) ]
@@ -78,23 +68,66 @@ struct DataflowMetrics {
7868 total_memory_mb : f64 ,
7969}
8070
71+ /// Render a list of [`OutputEntry`] values to stdout in either table or JSON format.
72+ ///
73+ /// When `show_metrics` is `false` the Nodes, CPU and Memory columns are omitted.
74+ pub ( super ) fn display_entries (
75+ entries : & [ OutputEntry ] ,
76+ format : OutputFormat ,
77+ show_metrics : bool ,
78+ ) -> eyre:: Result < ( ) > {
79+ match format {
80+ OutputFormat :: Table => {
81+ let mut tw = TabWriter :: new ( std:: io:: stdout ( ) . lock ( ) ) ;
82+ if show_metrics {
83+ tw. write_all ( b"UUID\t Name\t Status\t Nodes\t CPU\t Memory\n " ) ?;
84+ } else {
85+ tw. write_all ( b"UUID\t Name\t Status\n " ) ?;
86+ }
87+ for entry in entries {
88+ let status = match entry. status {
89+ DataflowStatus :: Running => "Running" ,
90+ DataflowStatus :: Finished => "Succeeded" ,
91+ DataflowStatus :: Failed => "Failed" ,
92+ } ;
93+ if show_metrics {
94+ tw. write_all (
95+ format ! (
96+ "{}\t {}\t {}\t {}\t {}\t {}\n " ,
97+ entry. uuid,
98+ entry. name,
99+ status,
100+ entry. nodes,
101+ format!( "{:.1}%" , entry. cpu) ,
102+ format!( "{:.1} GB" , entry. memory) ,
103+ )
104+ . as_bytes ( ) ,
105+ ) ?;
106+ } else {
107+ tw. write_all (
108+ format ! ( "{}\t {}\t {}\n " , entry. uuid, entry. name, status) . as_bytes ( ) ,
109+ ) ?;
110+ }
111+ }
112+ tw. flush ( ) ?;
113+ }
114+ OutputFormat :: Json => {
115+ for entry in entries {
116+ println ! ( "{}" , serde_json:: to_string( entry) ?) ;
117+ }
118+ }
119+ }
120+ Ok ( ( ) )
121+ }
122+
81123async fn list (
82124 client : & CliControlClient ,
83125 format : OutputFormat ,
84126 status_filter : Option < String > ,
85127 name_filter : Option < String > ,
86128 sort_by : Option < String > ,
87- clean : bool ,
88129) -> Result < ( ) , eyre:: ErrReport > {
89- let list = if !clean {
90- query_running_dataflows ( client) . await
91- } else {
92- rpc (
93- "clean finished dataflows" ,
94- client. clean ( tarpc:: context:: current ( ) ) ,
95- )
96- . await
97- } ?;
130+ let list = query_running_dataflows ( client) . await ?;
98131
99132 // Get node information via tarpc
100133 let node_infos = rpc (
@@ -197,39 +230,5 @@ async fn list(
197230 }
198231 }
199232
200- match format {
201- OutputFormat :: Table => {
202- let mut tw = TabWriter :: new ( std:: io:: stdout ( ) . lock ( ) ) ;
203- // Header
204- tw. write_all ( format ! ( "UUID\t Name\t Status\t Nodes\t CPU\t Memory\n " ) . as_bytes ( ) ) ?;
205- for entry in entries {
206- let status = match entry. status {
207- DataflowStatus :: Running => "Running" ,
208- DataflowStatus :: Finished => "Succeeded" ,
209- DataflowStatus :: Failed => "Failed" ,
210- } ;
211-
212- tw. write_all (
213- format ! (
214- "{}\t {}\t {}\t {}\t {}\t {}\n " ,
215- entry. uuid,
216- entry. name,
217- status,
218- entry. nodes,
219- format!( "{:.1}%" , entry. cpu) ,
220- format!( "{:.1} GB" , entry. memory)
221- )
222- . as_bytes ( ) ,
223- ) ?;
224- }
225- tw. flush ( ) ?;
226- }
227- OutputFormat :: Json => {
228- for entry in entries {
229- println ! ( "{}" , serde_json:: to_string( & entry) ?) ;
230- }
231- }
232- }
233-
234- Ok ( ( ) )
233+ display_entries ( & entries, format, true )
235234}
0 commit comments