swarm-controller: builder-runs handlers take their own sub-state via FromRef
This commit is contained in:
parent
a8c1c0f5c2
commit
c3773828c9
1 changed files with 21 additions and 3 deletions
|
|
@ -12,7 +12,7 @@ use std::future::Future;
|
|||
use anyhow::Context as _;
|
||||
use async_nats::jetstream::kv::Store;
|
||||
use axum::Json;
|
||||
use axum::extract::{Path, State};
|
||||
use axum::extract::{FromRef, Path, State};
|
||||
use axum::http::StatusCode;
|
||||
use problem_details::ProblemDetails;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -243,6 +243,24 @@ async fn open(client: Option<&async_nats::Client>) -> Result<Store, Unreachable>
|
|||
.map_err(|e| Unreachable(format!("{e:#}")))
|
||||
}
|
||||
|
||||
/// What the build-run routes may reach of [`AppState`]: the swarm builder's
|
||||
/// finished builds.
|
||||
///
|
||||
/// Derived per request from [`AppState`] (`FromRef`), so the field is a clone
|
||||
/// of the same `Builds` and nothing is held twice.
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct BuildsState {
|
||||
pub(crate) builds: Builds,
|
||||
}
|
||||
|
||||
impl FromRef<AppState> for BuildsState {
|
||||
fn from_ref(state: &AppState) -> Self {
|
||||
Self {
|
||||
builds: state.builds.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// List the swarm builder's finished builds.
|
||||
#[utoipa::path(
|
||||
get,
|
||||
|
|
@ -258,7 +276,7 @@ async fn open(client: Option<&async_nats::Client>) -> Result<Store, Unreachable>
|
|||
tag = "builder"
|
||||
)]
|
||||
pub(crate) async fn get_runs(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<BuildsState>,
|
||||
) -> Result<Json<Vec<BuildRecord>>, ProblemDetails> {
|
||||
state.builds.list().await.map(Json)
|
||||
}
|
||||
|
|
@ -279,7 +297,7 @@ pub(crate) async fn get_runs(
|
|||
tag = "builder"
|
||||
)]
|
||||
pub(crate) async fn get_run(
|
||||
State(state): State<AppState>,
|
||||
State(state): State<BuildsState>,
|
||||
Path(id): Path<String>,
|
||||
) -> Result<Json<BuildRecord>, ProblemDetails> {
|
||||
state
|
||||
|
|
|
|||
Loading…
Reference in a new issue