MCPcopy Create free account
hub / github.com/Qovery/engine / exec_with_abort

Method exec_with_abort

lib-engine/src/cmd/command.rs:212–386  ·  view source on GitHub ↗
(
        &mut self,
        stdout_output: &mut STDOUT,
        stderr_output: &mut STDERR,
        abort_notifier: &CommandKiller,
    )

Source from the content-addressed store, hash-verified

210 }
211
212 fn exec_with_abort<STDOUT, STDERR>(
213 &mut self,
214 stdout_output: &mut STDOUT,
215 stderr_output: &mut STDERR,
216 abort_notifier: &CommandKiller,
217 ) -> Result<(), CommandError>
218 where
219 STDOUT: FnMut(String),
220 STDERR: FnMut(String),
221 {
222 info!("command: {:?}", self.command);
223 let mut cmd_handle = self
224 .command
225 .stdout(Stdio::piped())
226 .stderr(Stdio::piped())
227 .spawn()
228 .map_err(ExecutionError)?;
229
230 // Read stdout/stderr until timeout is reached
231 let reader_timeout = Duration::from_secs(1);
232 let stdout = cmd_handle
233 .stdout
234 .take()
235 .ok_or_else(|| ExecutionError(Error::new(ErrorKind::BrokenPipe, "Cannot get stdout for command")))?;
236 let mut stdout_reader = BufReader::new(TimeoutReader::new(stdout, reader_timeout)).lines();
237
238 let stderr = cmd_handle
239 .stderr
240 .take()
241 .ok_or_else(|| ExecutionError(Error::new(ErrorKind::BrokenPipe, "Cannot get stderr for command")))?;
242 let mut stderr_reader = BufReader::new(TimeoutReader::new(
243 stderr,
244 Duration::from_secs(0), // don't block on stderr
245 ))
246 .lines();
247
248 let mut stdout_closed = false;
249 let mut stderr_closed = false;
250 let mut last_log_check = Instant::now();
251 let mut log_counter: u64 = 0;
252
253 while !stdout_closed || !stderr_closed {
254 // We should abort and kill the process
255 if abort_notifier.should_abort().is_some() {
256 break;
257 }
258
259 // Read on stdout first
260 while !stdout_closed {
261 let line = match stdout_reader.next() {
262 Some(line) => line,
263 None => {
264 // Stdout has been closed
265 stdout_closed = true;
266 break;
267 }
268 };
269

Callers 15

execute_govc_commandFunction · 0.45
run_eksctl_list_ovasFunction · 0.45
get_docker_imageMethod · 0.45
delete_docker_imageMethod · 0.45
list_docker_imagesMethod · 0.45
loginMethod · 0.45
execMethod · 0.45
exec_with_outputMethod · 0.45

Calls 4

should_abortMethod · 0.80
kindMethod · 0.45
killMethod · 0.45
is_cancelMethod · 0.45

Tested by 2

test_command_with_abortFunction · 0.36