2026-04-03 14:59:58 +08:00
|
|
|
use aether_gateway::build_execution_runtime_router_with_request_gates;
|
2026-03-24 15:12:56 +08:00
|
|
|
use aether_runtime::DistributedConcurrencyGate;
|
|
|
|
|
|
|
|
|
|
use crate::server::SpawnedServer;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Default)]
|
2026-04-03 14:59:58 +08:00
|
|
|
pub struct ExecutionRuntimeHarnessConfig {
|
2026-03-24 15:12:56 +08:00
|
|
|
pub max_in_flight_requests: Option<usize>,
|
|
|
|
|
pub distributed_request_gate: Option<DistributedConcurrencyGate>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2026-04-03 14:59:58 +08:00
|
|
|
pub struct ExecutionRuntimeHarness {
|
2026-03-24 15:12:56 +08:00
|
|
|
server: SpawnedServer,
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-03 14:59:58 +08:00
|
|
|
impl ExecutionRuntimeHarness {
|
|
|
|
|
pub async fn start(config: ExecutionRuntimeHarnessConfig) -> Result<Self, String> {
|
2026-03-24 15:12:56 +08:00
|
|
|
Self::start_with_server(config, None).await
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-03 14:59:58 +08:00
|
|
|
pub async fn start_on_port(
|
|
|
|
|
config: ExecutionRuntimeHarnessConfig,
|
|
|
|
|
port: u16,
|
|
|
|
|
) -> Result<Self, String> {
|
2026-03-24 15:12:56 +08:00
|
|
|
Self::start_with_server(config, Some(port)).await
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn start_with_server(
|
2026-04-03 14:59:58 +08:00
|
|
|
config: ExecutionRuntimeHarnessConfig,
|
2026-03-24 15:12:56 +08:00
|
|
|
port: Option<u16>,
|
|
|
|
|
) -> Result<Self, String> {
|
2026-04-03 14:59:58 +08:00
|
|
|
let router = build_execution_runtime_router_with_request_gates(
|
2026-03-24 15:12:56 +08:00
|
|
|
config.max_in_flight_requests,
|
|
|
|
|
config.distributed_request_gate,
|
|
|
|
|
);
|
|
|
|
|
let server = match port {
|
|
|
|
|
Some(port) => SpawnedServer::start_on_port(port, router)
|
|
|
|
|
.await
|
2026-04-03 14:59:58 +08:00
|
|
|
.map_err(|err| format!("failed to start execution runtime harness: {err}"))?,
|
2026-03-24 15:12:56 +08:00
|
|
|
None => SpawnedServer::start(router)
|
|
|
|
|
.await
|
2026-04-03 14:59:58 +08:00
|
|
|
.map_err(|err| format!("failed to start execution runtime harness: {err}"))?,
|
2026-03-24 15:12:56 +08:00
|
|
|
};
|
|
|
|
|
Ok(Self { server })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn base_url(&self) -> &str {
|
|
|
|
|
self.server.base_url()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn port(&self) -> u16 {
|
|
|
|
|
self.server.port()
|
|
|
|
|
}
|
|
|
|
|
}
|