Skip to content

Commit 1642cd6

Browse files
committed
refactor(aggregator): update stop signal in metric server of 'serve' command
1 parent 56e8700 commit 1642cd6

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

mithril-aggregator/src/commands/serve_command.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use clap::Parser;
1313
use config::{builder::DefaultState, ConfigBuilder, Map, Source, Value};
1414

1515
use slog::{crit, debug, info, warn, Logger};
16-
use tokio::{sync::oneshot, task::JoinSet};
16+
use tokio::task::JoinSet;
1717

1818
use mithril_cli_helper::{
1919
register_config_value, register_config_value_bool, register_config_value_option,
@@ -255,7 +255,7 @@ impl ServeCommand {
255255
.get_metrics_service()
256256
.await
257257
.with_context(|| "Metrics service initialization error")?;
258-
let (metrics_server_shutdown_tx, metrics_server_shutdown_rx) = oneshot::channel();
258+
let stop_rx_clone = stop_rx.clone();
259259
if config.enable_metrics_server {
260260
let metrics_logger = root_logger.clone();
261261
join_set.spawn(async move {
@@ -265,7 +265,7 @@ impl ServeCommand {
265265
metrics_service,
266266
metrics_logger.clone(),
267267
)
268-
.start(metrics_server_shutdown_rx)
268+
.start(stop_rx_clone)
269269
.await
270270
.map_err(|e| anyhow!(e));
271271

@@ -280,15 +280,13 @@ impl ServeCommand {
280280
crit!(root_logger, "A critical error occurred"; "error" => e);
281281
}
282282

283-
metrics_server_shutdown_tx
284-
.send(())
285-
.map_err(|e| anyhow!("Metrics server shutdown signal could not be sent: {e:?}"))?;
286-
287283
// Stop servers
288284
join_set.shutdown().await;
289285

290286
// Send the stop signal
291-
let _ = stop_tx.send(());
287+
stop_tx
288+
.send(())
289+
.map_err(|e| anyhow!("Stop signal could not be sent: {e:?}"))?;
292290

293291
if !preload_task.is_finished() {
294292
preload_task.abort();

0 commit comments

Comments
 (0)