Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions objectstore-server/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,14 @@ impl App {
let service =
ServiceExt::<Request>::into_make_service_with_connect_info::<SocketAddr>(router);

let server = async move {
if graceful_shutdown {
let guard = elegant_departure::get_shutdown_guard().shutdown_on_drop();
let guard = if graceful_shutdown {
Some(elegant_departure::get_shutdown_guard())
Comment on lines +116 to +117
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just noticing now that you made this configurable recently.
why would you ever not want to enable this?

} else {
None
};

let server = async {
if let Some(ref guard) = guard {
axum::serve(listener, service)
.with_graceful_shutdown(guard.wait_owned())
.await
Expand Down
2 changes: 1 addition & 1 deletion objectstore-server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The storage server component.
//!
//! This builds on top of the [`objectstore-service`], and exposes the underlying storage layer as
//! This builds on top of the [`objectstore_service`], and exposes the underlying storage layer as
//! an `HTTP` layer which can serve files directly to *external clients* and our SDK.

pub mod config;
Expand Down
26 changes: 16 additions & 10 deletions objectstore-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The storage server component.
//!
//! This builds on top of the [`objectstore-service`], and exposes the underlying storage layer as
//! This builds on top of the [`objectstore_service`], and exposes the underlying storage layer as
//! an `HTTP` layer which can serve files directly to *external clients* and our SDK.
#![warn(missing_docs)]
#![warn(missing_debug_implementations)]
Expand Down Expand Up @@ -42,27 +42,33 @@ fn main() -> Result<()> {
.expect("Failed to install rustls crypto provider");

let metrics_guard = maybe_initialize_metrics(&config)?;
let metrics_handle = async move {
match metrics_guard {
Some(metrics_guard) => metrics_guard.flush(None).await,
None => Ok(()),
}
};

runtime.block_on(async move {
let state = State::new(config).await?;
let server_handle = tokio::spawn(http::server(state));

tokio::spawn(async move {
elegant_departure::get_shutdown_guard().wait().await;
tracing::info!("shutting down ...");
});

elegant_departure::tokio::depart()
.on_termination()
.on_sigint()
.on_signal(SignalKind::hangup())
.on_signal(SignalKind::quit())
.await;

let (server_result, metrics_result) = tokio::join!(server_handle, metrics_handle);
server_result??;
metrics_result?;
if let Err(error) = server_handle.await.map_err(From::from).flatten() {
tracing::error!(
error = error.as_ref() as &dyn std::error::Error,
"web server failed"
);
}

if let Some(metrics_guard) = metrics_guard {
metrics_guard.flush(None).await.ok();
}

tracing::info!("shutdown complete");

Expand Down
Loading