1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apach
910//! Health check HTTP endpoints.
1112use axum::Extension;
13use axum::extract::Query;
14use axum::response::IntoResponse;
15use futures::FutureExt;
16use http::StatusCode;
17use serde::Deserialize;
1819use crate::http::Delayed;
2021/// Query parameters for [`handle_ready`].
22#[derive(Deserialize)]
23pub struct ReadyParams {
24/// Whether to wait for readiness or to return immediately if unready.
25#[serde(default)]
26wait: bool,
27}
2829/// Handles a readiness probe.
30pub async fn handle_ready(
31 Extension(client): Extension<Delayed<mz_adapter::Client>>,
32 query: Query<ReadyParams>,
33) -> impl IntoResponse {
34// `environmentd` is ready to serve queries when the adapter client is
35 // available.
36let is_ready = if query.wait {
37let _ = client.await;
38true
39} else {
40 client.now_or_never().is_some()
41 };
42match is_ready {
43false => (StatusCode::SERVICE_UNAVAILABLE, "not ready"),
44true => (StatusCode::OK, "ready"),
45 }
46}