@@ -74,39 +74,39 @@ impl Rrd {
74
74
75
75
impl Example {
76
76
fn build ( self , progress : & MultiProgress , output_dir : & Path ) -> anyhow:: Result < PathBuf > {
77
- let rrd_path = output_dir . join ( & self . name ) . with_extension ( "rrd" ) ;
77
+ let tempdir = tempfile :: tempdir ( ) ? ;
78
78
79
- let mut cmd = Command :: new ( "python3" ) ;
80
- cmd. arg ( "-m" ) . arg ( & self . name ) ;
81
- cmd. arg ( "--save" ) . arg ( & rrd_path) ;
82
- cmd. args ( self . script_args ) ;
83
-
84
- let final_args = cmd
85
- . get_args ( )
86
- . map ( |arg| arg. to_string_lossy ( ) . to_string ( ) )
87
- . collect :: < Vec < _ > > ( ) ;
79
+ let initial_rrd_path = tempdir. path ( ) . join ( & self . name ) . with_extension ( "rrd" ) ;
88
80
89
- // Configure flushing so that:
90
- // * the resulting file size is deterministic
91
- // * the file is chunked into small batches for better streaming
92
- cmd. env ( "RERUN_FLUSH_TICK_SECS" , 1_000_000_000 . to_string ( ) ) ;
93
- cmd . env ( "RERUN_FLUSH_NUM_BYTES" , ( 128 * 1024 ) . to_string ( ) ) ;
81
+ {
82
+ let mut cmd = Command :: new ( "python3" ) ;
83
+ cmd . arg ( "-m" ) . arg ( & self . name ) ;
84
+ cmd. arg ( "--save" ) . arg ( & initial_rrd_path ) ;
85
+ cmd . args ( self . script_args ) ;
94
86
95
- let output = wait_for_output ( cmd, & self . name , progress) ?;
87
+ // Configure flushing so that:
88
+ // * the resulting file size is deterministic
89
+ // * the file is chunked into small batches for better streaming
90
+ cmd. env ( "RERUN_FLUSH_TICK_SECS" , 1_000_000_000 . to_string ( ) ) ;
91
+ cmd. env ( "RERUN_FLUSH_NUM_BYTES" , ( 128 * 1024 ) . to_string ( ) ) ;
96
92
97
- if output. status . success ( ) {
98
- Ok ( rrd_path)
99
- } else {
100
- anyhow:: bail!(
101
- "Failed to run `python3 {}`: \
102
- \n stdout: \
103
- \n {} \
104
- \n stderr: \
105
- \n {}",
106
- final_args. join( " " ) ,
107
- String :: from_utf8( output. stdout) ?,
108
- String :: from_utf8( output. stderr) ?,
109
- ) ;
93
+ wait_for_output ( cmd, & self . name , progress) ?;
110
94
}
95
+
96
+ // Now run compaction on the result:
97
+ let final_rrd_path = output_dir. join ( & self . name ) . with_extension ( "rrd" ) ;
98
+
99
+ let mut cmd = Command :: new ( "python3" ) ;
100
+ cmd. arg ( "-m" ) . arg ( "rerun" ) ;
101
+ cmd. arg ( "rrd" ) ;
102
+ cmd. arg ( "compact" ) ;
103
+ // Small chunks for better streaming:
104
+ cmd. arg ( "--max-bytes" ) . arg ( ( 128 * 1024 ) . to_string ( ) ) ;
105
+ cmd. arg ( & initial_rrd_path) ;
106
+ cmd. arg ( "-o" ) . arg ( & final_rrd_path) ;
107
+
108
+ wait_for_output ( cmd, & format ! ( "{} compaction" , self . name) , progress) ?;
109
+
110
+ Ok ( final_rrd_path)
111
111
}
112
112
}
0 commit comments