add builders, fix sleep
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
/target
|
||||
.cargo-cache
|
||||
|
||||
5
Dockerfile.arm
Normal file
5
Dockerfile.arm
Normal 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
7
Makefile
Normal 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 .
|
||||
10
src/api.rs
10
src/api.rs
@@ -257,7 +257,7 @@ async fn get_state(
|
||||
let state_str = match current_state {
|
||||
MachineState::Boot => "Boot",
|
||||
MachineState::Primary => "Primary",
|
||||
MachineState::Fallback => "Fallback",
|
||||
MachineState::Fallback => "Secondary",
|
||||
};
|
||||
|
||||
// Get ping statistics from state machine
|
||||
@@ -280,10 +280,10 @@ async fn set_state(
|
||||
) -> Result<Json<StateResponse>, ErrorResponse> {
|
||||
let target_state = payload.state.to_lowercase();
|
||||
|
||||
if target_state != "primary" && target_state != "fallback" {
|
||||
if target_state != "primary" && target_state != "secondary" {
|
||||
return Err(ErrorResponse {
|
||||
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 new_state = match target_state.as_str() {
|
||||
"primary" => MachineState::Primary,
|
||||
"fallback" => MachineState::Fallback,
|
||||
"secondary" => MachineState::Fallback,
|
||||
_ => unreachable!(), // Already validated above
|
||||
};
|
||||
|
||||
@@ -316,7 +316,7 @@ async fn set_state(
|
||||
let state_str = match new_state {
|
||||
MachineState::Boot => "Boot",
|
||||
MachineState::Primary => "Primary",
|
||||
MachineState::Fallback => "Fallback",
|
||||
MachineState::Fallback => "Secondary",
|
||||
};
|
||||
|
||||
let primary_stats = PingStats::from_history(&state_machine.primary_history);
|
||||
|
||||
21
src/main.rs
21
src/main.rs
@@ -189,6 +189,16 @@ async fn main_service(
|
||||
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
|
||||
loop {
|
||||
tokio::select! {
|
||||
@@ -228,15 +238,8 @@ async fn main_service(
|
||||
break;
|
||||
}
|
||||
|
||||
// Check termination flag
|
||||
_ = tokio::task::spawn_blocking({
|
||||
let term = Arc::clone(&term);
|
||||
move || {
|
||||
while !term.load(Ordering::Relaxed) {
|
||||
std::thread::sleep(Duration::from_millis(100));
|
||||
}
|
||||
}
|
||||
}) => {
|
||||
// Check termination flag (now just waits for the already spawned task)
|
||||
_ = &mut term_checker => {
|
||||
info!("Received termination signal");
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user