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
|
|
@ -37,7 +37,7 @@ use futures_util::stream::BoxStream;
|
|||
use futures_util::{Stream, StreamExt as _};
|
||||
use swarm_queue_client::agent_term;
|
||||
|
||||
use crate::AppState;
|
||||
use crate::routes::AppState;
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
|
|
@ -68,19 +68,21 @@ pub(crate) async fn stream_agent_term(
|
|||
headers: HeaderMap,
|
||||
) -> 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
|
||||
|
|
@ -92,12 +94,12 @@ pub(crate) async fn stream_agent_term(
|
|||
.map_err(|e| {
|
||||
let detail = format!("{e:#}");
|
||||
tracing::warn!(%agent, error = %detail, "term 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"),
|
||||
)
|
||||
|
|
@ -110,7 +112,7 @@ pub(crate) async fn stream_agent_term(
|
|||
// 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),
|
||||
)
|
||||
|
|
@ -277,7 +279,7 @@ pub(crate) async fn subscribe(
|
|||
) -> Result<async_nats::Subscriber, problem_details::ProblemDetails> {
|
||||
let subscriber = client.subscribe(subject.clone()).await.map_err(|e| {
|
||||
tracing::warn!(%subject, error = %e, "{what} stream: subscribe failed");
|
||||
crate::error_problem(
|
||||
crate::routes::error_problem(
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
&format!("subscribing to {subject} failed: {e}"),
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue