From c3773828c929541d2cf8b06b86994d673092079c Mon Sep 17 00:00:00 2001 From: atlas Date: Sun, 29 Nov 2026 12:51:29 +0100 Subject: [PATCH] swarm-controller: builder-runs handlers take their own sub-state via FromRef --- swarm-controller/src/deploy/builder/runs.rs | 24 ++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/swarm-controller/src/deploy/builder/runs.rs b/swarm-controller/src/deploy/builder/runs.rs index bf6377a4b..73a791d77 100644 --- a/swarm-controller/src/deploy/builder/runs.rs +++ b/swarm-controller/src/deploy/builder/runs.rs @@ -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 .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 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 tag = "builder" )] pub(crate) async fn get_runs( - State(state): State, + State(state): State, ) -> Result>, 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, + State(state): State, Path(id): Path, ) -> Result, ProblemDetails> { state