Skip to content

Commit

Permalink
refactor(publisher): fix publisher signal listener
Browse files Browse the repository at this point in the history
  • Loading branch information
Jurshsmith committed Nov 11, 2024
1 parent be031ba commit 4a44f35
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions crates/fuel-streams-publisher/src/publisher_shutdown.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::{sync::Arc, time::Duration};

use tokio::sync::{broadcast, OnceCell};
use tokio::{
signal::unix::{signal, SignalKind},
sync::{broadcast, OnceCell},
};

// TODO: move into publisher module along with subjects

Expand Down Expand Up @@ -55,9 +58,22 @@ impl ShutdownController {
}

pub fn spawn_signal_listener(self: Arc<Self>) {
let sender = self.sender.clone();
tokio::spawn(async move {
if let Ok(()) = tokio::signal::ctrl_c().await {
let _ = self.initiate_shutdown();
let mut sigint =
signal(SignalKind::interrupt()).expect("shutdown_listener");
let mut sigterm =
signal(SignalKind::terminate()).expect("shutdown_listener");

tokio::select! {
_ = sigint.recv() => {
tracing::info!("Received SIGINT ...");
let _ = sender.send(());
}
_ = sigterm.recv() => {
tracing::info!("Received SIGTERM ...");
let _ = sender.send(());
}
}
});
}
Expand Down

0 comments on commit 4a44f35

Please sign in to comment.