swarm-controller: split main.rs into jobq, routes and startup modules
no behaviour change: a pure move of items and tests into new modules, plus visibility edits (pub(crate)) and path updates in sibling modules that named crate-root items. same routes, same OpenAPI, 561 tests before and after. why: #5470, new features stop landing in one 6.4k-line file by default. files outside swarm-controller/src: docs/agent-lifecycle/agent-roster.md, swarm-ui JobsPage.tsx and AgentsPage.tsx, nix/host-modules/swarm-controller.nix and swarm-grafana.nix hold comments that named main.rs for items that moved.
This commit is contained in:
parent
f0a6d6c042
commit
738dd1c95b
42 changed files with 6854 additions and 6680 deletions
|
|
@ -29,7 +29,7 @@ use axum::extract::{Path, State};
|
|||
use axum::response::sse::{Event, KeepAlive, Sse};
|
||||
use futures_util::{Stream, StreamExt as _};
|
||||
|
||||
use crate::AppState;
|
||||
use crate::routes::AppState;
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
|
|
@ -60,19 +60,21 @@ pub(crate) async fn stream_agent_state(
|
|||
Path(agent): Path<String>,
|
||||
) -> Result<Sse<impl Stream<Item = Result<Event, Infallible>>>, problem_details::ProblemDetails> {
|
||||
let Some(status) = state.status.as_ref() else {
|
||||
return Err(crate::error_problem(
|
||||
return Err(crate::routes::error_problem(
|
||||
axum::http::StatusCode::SERVICE_UNAVAILABLE,
|
||||
"no swarm queue is configured on this host",
|
||||
));
|
||||
};
|
||||
let Some(agent_status) = state.agent_status.as_ref() else {
|
||||
return Err(crate::error_problem(
|
||||
return Err(crate::routes::error_problem(
|
||||
axum::http::StatusCode::SERVICE_UNAVAILABLE,
|
||||
"no agent-status reader is configured on this host",
|
||||
));
|
||||
};
|
||||
let agent = hive_types::Ident::parse(&agent)
|
||||
.map_err(|reason| crate::error_problem(axum::http::StatusCode::BAD_REQUEST, reason))?
|
||||
.map_err(|reason| {
|
||||
crate::routes::error_problem(axum::http::StatusCode::BAD_REQUEST, reason)
|
||||
})?
|
||||
.into_string();
|
||||
|
||||
// One-agent "roster": reuses `AgentStatusReader::view`'s already-tested
|
||||
|
|
@ -84,12 +86,12 @@ pub(crate) async fn stream_agent_state(
|
|||
.map_err(|e| {
|
||||
let detail = format!("{e:#}");
|
||||
tracing::warn!(%agent, error = %detail, "state stream: reading agent status failed");
|
||||
crate::error_problem(axum::http::StatusCode::INTERNAL_SERVER_ERROR, &detail)
|
||||
crate::routes::error_problem(axum::http::StatusCode::INTERNAL_SERVER_ERROR, &detail)
|
||||
})?
|
||||
.into_iter()
|
||||
.find_map(|row| row.hive)
|
||||
.ok_or_else(|| {
|
||||
crate::error_problem(
|
||||
crate::routes::error_problem(
|
||||
axum::http::StatusCode::NOT_FOUND,
|
||||
&format!("{agent:?} has never reported to the swarm"),
|
||||
)
|
||||
|
|
@ -101,7 +103,7 @@ pub(crate) async fn stream_agent_state(
|
|||
// against a queue that is not there — the honest answer is 503, the
|
||||
// same shape every other queue-backed route here already uses.
|
||||
swarm_queue_client::ensure_connected(&client).map_err(|e| {
|
||||
crate::error_problem(
|
||||
crate::routes::error_problem(
|
||||
axum::http::StatusCode::SERVICE_UNAVAILABLE,
|
||||
&swarm_queue_client::chain(&e),
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue