feat: make network non blocking and fix deploy script

This commit is contained in:
Jet Pham 2025-06-06 18:51:59 -07:00
parent 0f0d0513cb
commit 9bc01997d7
No known key found for this signature in database
2 changed files with 12 additions and 3 deletions

View file

@ -7,6 +7,7 @@ echo "Building for Raspberry Pi..."
cross build --release --target aarch64-unknown-linux-gnu cross build --release --target aarch64-unknown-linux-gnu
echo "Copying to Raspberry Pi..." echo "Copying to Raspberry Pi..."
ssh noisebridge@noisebell.local "mkdir -p ~/noisebell"
scp target/aarch64-unknown-linux-gnu/release/noisebell noisebridge@noisebell.local:~/noisebell/ scp target/aarch64-unknown-linux-gnu/release/noisebell noisebridge@noisebell.local:~/noisebell/
scp endpoints.json noisebridge@noisebell.local:/home/noisebridge/noisebell/endpoints.json scp endpoints.json noisebridge@noisebell.local:/home/noisebridge/noisebell/endpoints.json

View file

@ -61,9 +61,12 @@ async fn main() -> Result<()> {
let server_addr = format!("127.0.0.1:{}", DEFAULT_SERVER_PORT); let server_addr = format!("127.0.0.1:{}", DEFAULT_SERVER_PORT);
info!("Starting API server on http://{}", server_addr); info!("Starting API server on http://{}", server_addr);
let listener = tokio::net::TcpListener::bind(&server_addr).await?; let server = tokio::spawn(async move {
axum::serve(listener, app.into_make_service()) let listener = tokio::net::TcpListener::bind(&server_addr).await?;
.await?; axum::serve(listener, app.into_make_service())
.await?;
Ok::<_, anyhow::Error>(())
});
let callback = move |event: gpio::CircuitEvent| { let callback = move |event: gpio::CircuitEvent| {
info!("Circuit state changed: {:?}", event); info!("Circuit state changed: {:?}", event);
@ -81,6 +84,11 @@ async fn main() -> Result<()> {
error!("GPIO monitoring error: {}", e); error!("GPIO monitoring error: {}", e);
} }
// Wait for the server to complete (it shouldn't unless there's an error)
if let Err(e) = server.await? {
error!("Server error: {}", e);
}
Ok(()) Ok(())
} }