| 25 | } |
| 26 | |
| 27 | pub async fn wait_for_healthy(timeout: Duration) -> Result<(), String> { |
| 28 | let start = Instant::now(); |
| 29 | let mut last_output: String; |
| 30 | |
| 31 | loop { |
| 32 | let (output, code) = run_cli(&["status"]).await; |
| 33 | let clean = strip_ansi(&output); |
| 34 | let lower = clean.to_lowercase(); |
| 35 | if code == 0 |
| 36 | && (lower.contains("healthy") |
| 37 | || lower.contains("running") |
| 38 | || lower.contains("connected")) |
| 39 | { |
| 40 | return Ok(()); |
| 41 | } |
| 42 | last_output = clean; |
| 43 | |
| 44 | if start.elapsed() > timeout { |
| 45 | return Err(format!( |
| 46 | "gateway did not become healthy within {}s. Last output:\n{last_output}", |
| 47 | timeout.as_secs() |
| 48 | )); |
| 49 | } |
| 50 | sleep(Duration::from_secs(2)).await; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | pub async fn sandbox_names() -> Result<Vec<String>, String> { |
| 55 | let (output, code) = run_cli(&["sandbox", "list", "--names"]).await; |