mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-04 01:24:09 +02:00
waiting
This commit is contained in:
parent
c2f85e009e
commit
1d20b7937c
5 changed files with 154 additions and 29 deletions
21
src/php.rs
21
src/php.rs
|
|
@ -3,9 +3,13 @@ use crate::image::pull_image;
|
|||
use bollard::container::{Config, CreateContainerOptions, NetworkingConfig};
|
||||
use bollard::models::{EndpointSettings, HostConfig};
|
||||
use bollard::Docker;
|
||||
use color_eyre::Result;
|
||||
use color_eyre::{eyre::WrapErr, Report, Result};
|
||||
use maplit::hashmap;
|
||||
use reqwest::{Client, Url};
|
||||
use std::net::IpAddr;
|
||||
use std::str::FromStr;
|
||||
use std::time::Duration;
|
||||
use tokio::time::{sleep, timeout};
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
#[allow(dead_code)]
|
||||
|
|
@ -87,6 +91,21 @@ impl PhpVersion {
|
|||
docker.start_container::<String>(&id, None).await?;
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
pub async fn wait_for_start(&self, ip: Option<IpAddr>) -> Result<()> {
|
||||
let client = Client::new();
|
||||
let url = Url::parse(&format!(
|
||||
"http://{}/status.php",
|
||||
ip.ok_or(Report::msg("Container not running"))?
|
||||
))?;
|
||||
timeout(Duration::from_secs(5), async {
|
||||
while !client.get(url.clone()).send().await.is_ok() {
|
||||
sleep(Duration::from_millis(100)).await
|
||||
}
|
||||
})
|
||||
.await
|
||||
.wrap_err("Timeout after 5 seconds")
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for PhpVersion {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue