MCPcopy Create free account
hub / github.com/hashintel/hash / wait_healthcheck

Function wait_healthcheck

apps/hash-graph/src/subcommand/mod.rs:184–208  ·  view source on GitHub ↗
(
    func: F,
    args: &HealthcheckArgs,
)

Source from the content-addressed store, hash-verified

182}
183
184pub async fn wait_healthcheck<F, Ret>(
185 func: F,
186 args: &HealthcheckArgs,
187) -> Result<(), Report<HealthcheckError>>
188where
189 F: Fn() -> Ret + Send,
190 Ret: Future<Output = Result<(), Report<HealthcheckError>>> + Send,
191{
192 let expected_end_time = args
193 .timeout
194 .map(|timeout| Instant::now() + Duration::from_secs(timeout));
195
196 loop {
197 if func().await.is_ok() {
198 return Ok(());
199 }
200 ensure!(args.wait, HealthcheckError::NotHealthy);
201 if let Some(end_time) = expected_end_time
202 && Instant::now() > end_time
203 {
204 return Err(HealthcheckError::Timeout.into());
205 }
206 sleep(Duration::from_secs(1)).await;
207 }
208}

Callers 3

serverFunction · 0.85
type_fetcherFunction · 0.85
admin_serverFunction · 0.85

Calls 6

funcFunction · 0.85
OkInterface · 0.85
ErrInterface · 0.85
is_okMethod · 0.80
sleepFunction · 0.50
mapMethod · 0.45

Tested by

no test coverage detected