Execute a Docker command and return (stdout, stderr).
(
&self,
args: &[String],
)
| 44 | |
| 45 | /// Execute a Docker command and return (stdout, stderr). |
| 46 | async fn execute_docker_command( |
| 47 | &self, |
| 48 | args: &[String], |
| 49 | ) -> Result<(Vec<u8>, Vec<u8>), anyhow::Error> { |
| 50 | retry::Retry::default() |
| 51 | .max_duration(DOCKER_RESOURCE_DUMP_TIMEOUT) |
| 52 | .retry_async(|_| { |
| 53 | let args = args.to_vec(); |
| 54 | async move { |
| 55 | let output = tokio::process::Command::new("docker") |
| 56 | .args(&args) |
| 57 | .output() |
| 58 | .await; |
| 59 | |
| 60 | match output { |
| 61 | Ok(output) if output.status.success() => { |
| 62 | RetryResult::Ok((output.stdout, output.stderr)) |
| 63 | } |
| 64 | Ok(output) => { |
| 65 | let err_msg = format!( |
| 66 | "Docker command failed: {:#}. Retrying...", |
| 67 | String::from_utf8_lossy(&output.stderr) |
| 68 | ); |
| 69 | warn!("{}", err_msg); |
| 70 | RetryResult::RetryableErr(anyhow::anyhow!(err_msg)) |
| 71 | } |
| 72 | Err(err) => { |
| 73 | let err_msg = format!("Failed to execute Docker command: {:#}", err); |
| 74 | warn!("{}", err_msg); |
| 75 | RetryResult::RetryableErr(anyhow::anyhow!(err_msg)) |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | }) |
| 80 | .await |
| 81 | } |
| 82 | |
| 83 | async fn dump_logs(&self) -> Result<(), anyhow::Error> { |
| 84 | let (stdout, stderr) = self |
no test coverage detected