feature: CancellationToken-based shutdowns (#5325)
* initial stub for ShutdownToken * attempting to start using new ShutdownManager in NymNode * migrated verloc tasks * added custom shutdown signal registration * integrated legacy task support * migrated additional tasks inside nym-node * removed import thats unused in wasm * apply review comments * windows fixes
This commit is contained in:
committed by
GitHub
parent
11d6ee2fdb
commit
102cd1033c
@@ -6,9 +6,7 @@ use axum::extract::ConnectInfo;
|
||||
use axum::middleware::AddExtension;
|
||||
use axum::serve::Serve;
|
||||
use axum::Router;
|
||||
use nym_task::TaskClient;
|
||||
use std::net::SocketAddr;
|
||||
use tracing::{debug, error};
|
||||
|
||||
pub use router::{api, HttpServerConfig, NymNodeRouter};
|
||||
|
||||
@@ -19,47 +17,4 @@ pub mod state;
|
||||
|
||||
type InnerService = IntoMakeServiceWithConnectInfo<Router, SocketAddr>;
|
||||
type ConnectInfoExt = AddExtension<Router, ConnectInfo<SocketAddr>>;
|
||||
pub type ServeService = Serve<InnerService, ConnectInfoExt>;
|
||||
|
||||
pub struct NymNodeHttpServer {
|
||||
task_client: Option<TaskClient>,
|
||||
inner: ServeService,
|
||||
}
|
||||
|
||||
impl NymNodeHttpServer {
|
||||
pub(crate) fn new(inner: ServeService) -> Self {
|
||||
NymNodeHttpServer {
|
||||
task_client: None,
|
||||
inner,
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn with_task_client(mut self, task_client: TaskClient) -> Self {
|
||||
self.task_client = Some(task_client);
|
||||
self
|
||||
}
|
||||
|
||||
async fn run_server_forever(server: ServeService) {
|
||||
if let Err(err) = server.await {
|
||||
error!("the HTTP server has terminated with the error: {err}");
|
||||
} else {
|
||||
error!("the HTTP server has terminated with producing any errors");
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run(self) {
|
||||
if let Some(mut task_client) = self.task_client {
|
||||
tokio::select! {
|
||||
_ = task_client.recv_with_delay() => {
|
||||
debug!("NymNodeHTTPServer: Received shutdown");
|
||||
}
|
||||
_ = Self::run_server_forever(self.inner) => { }
|
||||
}
|
||||
} else {
|
||||
Self::run_server_forever(self.inner).await
|
||||
}
|
||||
|
||||
debug!("NymNodeHTTPServer: Exiting");
|
||||
}
|
||||
}
|
||||
pub type NymNodeHttpServer = Serve<InnerService, ConnectInfoExt>;
|
||||
|
||||
@@ -175,12 +175,10 @@ impl NymNodeRouter {
|
||||
source,
|
||||
})?;
|
||||
|
||||
let axum_server = axum::serve(
|
||||
Ok(axum::serve(
|
||||
listener,
|
||||
self.inner
|
||||
.into_make_service_with_connect_info::<SocketAddr>(),
|
||||
);
|
||||
|
||||
Ok(NymNodeHttpServer::new(axum_server))
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user