Line data Source code
1 : use crate::compute_prewarm::LfcPrewarmStateWithProgress;
2 : use crate::http::JsonResponse;
3 : use axum::response::{IntoResponse, Response};
4 : use axum::{Json, http::StatusCode};
5 : use compute_api::responses::LfcOffloadState;
6 : type Compute = axum::extract::State<std::sync::Arc<crate::compute::ComputeNode>>;
7 :
8 0 : pub(in crate::http) async fn prewarm_state(compute: Compute) -> Json<LfcPrewarmStateWithProgress> {
9 0 : Json(compute.lfc_prewarm_state().await)
10 0 : }
11 :
12 : // Following functions are marked async for axum, as it's more convenient than wrapping these
13 : // in async lambdas at call site
14 :
15 0 : pub(in crate::http) async fn offload_state(compute: Compute) -> Json<LfcOffloadState> {
16 0 : Json(compute.lfc_offload_state())
17 0 : }
18 :
19 0 : pub(in crate::http) async fn prewarm(compute: Compute) -> Response {
20 0 : if compute.prewarm_lfc() {
21 0 : StatusCode::ACCEPTED.into_response()
22 : } else {
23 0 : JsonResponse::error(
24 0 : StatusCode::TOO_MANY_REQUESTS,
25 0 : "Multiple requests for prewarm are not allowed",
26 0 : )
27 : }
28 0 : }
29 :
30 0 : pub(in crate::http) async fn offload(compute: Compute) -> Response {
31 0 : if compute.offload_lfc() {
32 0 : StatusCode::ACCEPTED.into_response()
33 : } else {
34 0 : JsonResponse::error(
35 0 : StatusCode::TOO_MANY_REQUESTS,
36 0 : "Multiple requests for prewarm offload are not allowed",
37 0 : )
38 : }
39 0 : }
|