Watch
0
0
Fork
You've already forked hyperhive
0

swarm-controller: alerts and jobq-graph handlers take their own sub-state via FromRef

This commit is contained in:
atlas 2026-11-28 06:58:15 +01:00 • committed by mara
commit b9687c54f2

View file

@ -1,11 +1,32 @@
//! Read-only views of the swarm-level job graph.
use std::sync::{Arc, Mutex};
use axum::extract::FromRef;
use axum::{Json, extract::State};
use hive_jobq_wire::GraphWire as _;
use serde::Deserialize;
use crate::jobq::{SwarmNodeKind, SwarmResourceKind};
use crate::routes::AppState;
/// What the job-graph routes may reach of [`AppState`]: the scheduler.
///
/// Derived per request from [`AppState`] (`FromRef`), so the field is a clone
/// of the same `Arc` and nothing is held twice.
#[derive(Clone)]
pub(crate) struct JobqState {
pub(crate) jobq: Arc<Mutex<hive_jobq::scheduler::Scheduler<SwarmNodeKind, SwarmResourceKind>>>,
}
impl FromRef<AppState> for JobqState {
fn from_ref(state: &AppState) -> Self {
Self {
jobq: Arc::clone(&state.jobq),
}
}
}
/// Query params for `GET /api/jobq/graph` — `?states=` narrows to root
/// groups in the named states, same shape `hive_jobq_wire::parse_states`
/// parses.
@ -28,7 +49,7 @@ pub(crate) struct JobqGraphQuery {
tag = "jobq"
)]
pub(crate) async fn get_jobq_graph(
State(state): State<AppState>,
State(state): State<JobqState>,
axum::extract::Query(q): axum::extract::Query<JobqGraphQuery>,
) -> Json<Vec<hive_jobq_wire::GraphNode>> {
let states = hive_jobq_wire::parse_states(q.states.as_deref());
@ -53,7 +74,7 @@ pub(crate) async fn get_jobq_graph(
tag = "jobq"
)]
pub(crate) async fn get_jobq_rollup(
State(state): State<AppState>,
State(state): State<JobqState>,
) -> Json<Vec<hive_jobq_wire::StateCount>> {
let sched = state
.jobq