use std::time::Duration;
use super::READ_LIMIT;
use super::failures::{checked, engine_error};
use crate::Result;
use crate::cli::compose::{self, Project};
use crate::formats::ToolCx;
const UNPAUSED_HEALTH: Duration = Duration::from_secs(60);
const HEALTH_POLL: Duration = Duration::from_secs(1);
pub(super) async fn health_back(cx: &ToolCx<'_>, project: &Project<'_>, services: &[String]) -> Result<()> {
let deadline = tokio::time::Instant::now() + UNPAUSED_HEALTH;
loop {
let containers = checked(cx, compose::ps(&cx.read(READ_LIMIT), project).await, |e| engine_error("status", e)).await?;
let waiting = containers
.iter()
.any(|c| !c.one_off() && c.is_unhealthy() && services.iter().any(|s| s == c.service()));
if !waiting || tokio::time::Instant::now() >= deadline {
return Ok(());
}
tokio::time::sleep(HEALTH_POLL).await;
}
}