mirror of
https://codeberg.org/Toasterson/solstice-ci.git
synced 2026-04-10 13:20:41 +00:00
This commit introduces: - A heuristic to mark jobs as failed if VMs stop quickly without generating logs. - Improved configuration for runner URLs, including auto-detection of host IPs and default multi-OS runner URLs. - Updates to the orchestrator's HTTP routing for consistency. - New task scripts for Forge integration and updates to environment defaults for local development.
55 lines
1.7 KiB
Rust
55 lines
1.7 KiB
Rust
use axum::{extract::Path, http::StatusCode, response::{IntoResponse, Response}, routing::get, Router};
|
|
use std::net::SocketAddr;
|
|
use std::sync::Arc;
|
|
use tracing::{info, warn};
|
|
use uuid::Uuid;
|
|
|
|
use crate::persist::Persist;
|
|
|
|
#[derive(Clone)]
|
|
pub struct HttpState {
|
|
persist: Arc<Persist>,
|
|
}
|
|
|
|
pub fn build_router(persist: Arc<Persist>) -> Router {
|
|
let state = HttpState { persist };
|
|
Router::new()
|
|
.route("/jobs/{request_id}/logs", get(get_logs))
|
|
.with_state(state)
|
|
}
|
|
|
|
async fn get_logs(
|
|
Path(request_id): Path<String>,
|
|
axum::extract::State(state): axum::extract::State<HttpState>,
|
|
) -> Response {
|
|
let Ok(id) = Uuid::parse_str(&request_id) else {
|
|
return StatusCode::BAD_REQUEST.into_response();
|
|
};
|
|
if !state.persist.is_enabled() {
|
|
return (StatusCode::SERVICE_UNAVAILABLE, "persistence disabled").into_response();
|
|
}
|
|
match state.persist.get_logs_text(id).await {
|
|
Ok(Some(text)) => (
|
|
StatusCode::OK,
|
|
[(axum::http::header::CONTENT_TYPE, "text/plain; charset=utf-8")],
|
|
text,
|
|
)
|
|
.into_response(),
|
|
Ok(None) => StatusCode::NOT_FOUND.into_response(),
|
|
Err(e) => {
|
|
warn!(error = %e, request_id = %id, "failed to read logs");
|
|
StatusCode::INTERNAL_SERVER_ERROR.into_response()
|
|
}
|
|
}
|
|
}
|
|
|
|
pub async fn serve(addr: SocketAddr, persist: Arc<Persist>, shutdown: impl std::future::Future<Output = ()>) {
|
|
let app = build_router(persist);
|
|
info!(%addr, "http server starting");
|
|
let listener = tokio::net::TcpListener::bind(addr).await.expect("bind http");
|
|
let server = axum::serve(listener, app);
|
|
let _ = tokio::select! {
|
|
_ = server => {},
|
|
_ = shutdown => {},
|
|
};
|
|
}
|