add builders, fix sleep

This commit is contained in:
Michal Humpula
2026-03-01 07:28:56 +01:00
parent 940a86ff8c
commit 0cff05d623
5 changed files with 30 additions and 14 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
/target /target
.cargo-cache

5
Dockerfile.arm Normal file
View File

@@ -0,0 +1,5 @@
FROM rust:1.93.1-bullseye
RUN rustup target add aarch64-unknown-linux-gnu \
&& apt update \
&& apt install -y gcc-aarch64-linux-gnu

7
Makefile Normal file
View File

@@ -0,0 +1,7 @@
build: image
podman run -it --rm -v $(PWD):/app -v $(PWD)/.cargo-cache:/usr/local/cargo/registry -w /app route-switcher-builder:latest cargo build --target aarch64-unknown-linux-gnu
image:
podman build -f Dockerfile.arm -t route-switcher-builder:latest .

View File

@@ -257,7 +257,7 @@ async fn get_state(
let state_str = match current_state { let state_str = match current_state {
MachineState::Boot => "Boot", MachineState::Boot => "Boot",
MachineState::Primary => "Primary", MachineState::Primary => "Primary",
MachineState::Fallback => "Fallback", MachineState::Fallback => "Secondary",
}; };
// Get ping statistics from state machine // Get ping statistics from state machine
@@ -280,10 +280,10 @@ async fn set_state(
) -> Result<Json<StateResponse>, ErrorResponse> { ) -> Result<Json<StateResponse>, ErrorResponse> {
let target_state = payload.state.to_lowercase(); let target_state = payload.state.to_lowercase();
if target_state != "primary" && target_state != "fallback" { if target_state != "primary" && target_state != "secondary" {
return Err(ErrorResponse { return Err(ErrorResponse {
error: "Invalid state".to_string(), error: "Invalid state".to_string(),
message: "State must be 'primary' or 'fallback'".to_string(), message: "State must be 'primary' or 'secondary'".to_string(),
}); });
} }
@@ -293,7 +293,7 @@ async fn set_state(
let old_state = state_machine.get_state().clone(); let old_state = state_machine.get_state().clone();
let new_state = match target_state.as_str() { let new_state = match target_state.as_str() {
"primary" => MachineState::Primary, "primary" => MachineState::Primary,
"fallback" => MachineState::Fallback, "secondary" => MachineState::Fallback,
_ => unreachable!(), // Already validated above _ => unreachable!(), // Already validated above
}; };
@@ -316,7 +316,7 @@ async fn set_state(
let state_str = match new_state { let state_str = match new_state {
MachineState::Boot => "Boot", MachineState::Boot => "Boot",
MachineState::Primary => "Primary", MachineState::Primary => "Primary",
MachineState::Fallback => "Fallback", MachineState::Fallback => "Secondary",
}; };
let primary_stats = PingStats::from_history(&state_machine.primary_history); let primary_stats = PingStats::from_history(&state_machine.primary_history);

View File

@@ -189,6 +189,16 @@ async fn main_service(
None None
}; };
// Spawn the termination checker once, outside the select loop
let mut term_checker = tokio::task::spawn_blocking({
let term = Arc::clone(&term);
move || {
while !term.load(Ordering::Relaxed) {
std::thread::sleep(Duration::from_millis(100));
}
}
});
// Main event loop // Main event loop
loop { loop {
tokio::select! { tokio::select! {
@@ -228,15 +238,8 @@ async fn main_service(
break; break;
} }
// Check termination flag // Check termination flag (now just waits for the already spawned task)
_ = tokio::task::spawn_blocking({ _ = &mut term_checker => {
let term = Arc::clone(&term);
move || {
while !term.load(Ordering::Relaxed) {
std::thread::sleep(Duration::from_millis(100));
}
}
}) => {
info!("Received termination signal"); info!("Received termination signal");
break; break;
} }