File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -149,16 +149,29 @@ fn run_psql(
149
149
use std:: process:: { Command , Stdio } ;
150
150
151
151
let psql_script = config. gen_psql_script ( ) ;
152
- // TODO Redirect stdout and stderr to avoid polluting the worker logs.
153
152
let mut psql = Command :: new ( "psql" )
154
153
. arg ( database_url)
155
154
. current_dir ( export_dir)
156
155
. stdin ( Stdio :: piped ( ) )
156
+ . stdout ( Stdio :: null ( ) )
157
+ . stderr ( Stdio :: piped ( ) )
157
158
. spawn ( ) ?;
158
159
let mut stdin = psql. stdin . take ( ) . unwrap ( ) ;
159
- stdin. write_all ( psql_script. as_bytes ( ) ) ?;
160
- drop ( stdin) ;
161
- psql. wait ( ) ?;
160
+ let input_thread = std:: thread:: spawn ( move || -> std:: io:: Result < ( ) > {
161
+ stdin. write_all ( psql_script. as_bytes ( ) ) ?;
162
+ Ok ( ( ) )
163
+ } ) ;
164
+ let output = psql. wait_with_output ( ) ?;
165
+ input_thread. join ( ) . unwrap ( ) ?;
166
+ if !output. stderr . is_empty ( ) {
167
+ Err ( format ! (
168
+ "Error while executing psql: {}" ,
169
+ String :: from_utf8_lossy( & output. stderr)
170
+ ) ) ?;
171
+ }
172
+ if !output. status . success ( ) {
173
+ Err ( "psql did not finish successfully." ) ?;
174
+ }
162
175
Ok ( ( ) )
163
176
}
164
177
You can’t perform that action at this time.
0 commit comments