Skip to content

Commit

Permalink
chore: log webserver exit status
Browse files Browse the repository at this point in the history
  • Loading branch information
fetchfern committed Apr 23, 2024
1 parent 69e2ec9 commit 2b3f337
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 8 additions & 4 deletions crates/alerion_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ pub async fn alerion_main() -> anyhow::Result<()> {

//server_pool.create_server("0e4059ca-d79b-46a5-8ec4-95bd0736d150".try_into().unwrap()).await;

// there is a low likelyhood this will actually block, and if it does
// it will block only once for a short amount of time, so it's no big deal.
let webserver = webserver::serve(config);
let webserver_handle = tokio::spawn(async move {
let cfg = config.clone();
let result = webserver::serve(cfg).await;

let webserver_handle = tokio::spawn(webserver);
match result {
Ok(()) => tracing::info!("webserver exited gracefully"),
Err(e) => tracing::error!("webserver exited with an error: {e}"),
}
});

let mut handles = FuturesUnordered::new();
handles.push(webserver_handle);
Expand Down
7 changes: 4 additions & 3 deletions crates/alerion_core/src/webserver.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![deny(dead_code)]
use std::collections::HashSet;
use std::env::consts::{ARCH, OS};
use std::io;

use bitflags::bitflags;
use futures::{SinkExt, StreamExt};
Expand Down Expand Up @@ -265,7 +266,7 @@ async fn return_auth_details(Path(_identifier): Path<String>) -> impl IntoRespon
todo!()
}

pub async fn serve(config: AlerionConfig) {
pub async fn serve(config: AlerionConfig) -> io::Result<()> {
let system_endpoint = get(process_system_query)
.options(endpoint::make_sync(|_| StatusCode::NO_CONTENT))
.with(Cors::new().allow_credentials(true))
Expand All @@ -279,9 +280,9 @@ pub async fn serve(config: AlerionConfig) {
),
);

let _ = Server::new(TcpListener::bind((config.api.host, config.api.port)))
Server::new(TcpListener::bind((config.api.host, config.api.port)))
.run(api)
.await;
.await
}

pub mod middleware;

0 comments on commit 2b3f337

Please sign in to comment.