Skip to content

Commit

Permalink
fix: effective ctrl+c shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Aug 7, 2023
1 parent 7a0a59b commit 6c699b3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
7 changes: 5 additions & 2 deletions subgraph-radio/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use axum::Router;
use once_cell::sync::Lazy;
use prometheus::{core::Collector, Registry};
use prometheus::{IntCounterVec, IntGauge, IntGaugeVec, Opts};
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use std::{net::SocketAddr, str::FromStr};
use tracing::{debug, info};

Expand Down Expand Up @@ -124,7 +126,7 @@ pub async fn get_metrics() -> (StatusCode, String) {

/// Run the API server as well as Prometheus and a traffic generator
#[allow(dead_code)]
pub async fn handle_serve_metrics(host: String, port: u16) {
pub async fn handle_serve_metrics(host: String, port: u16, _running_program: Arc<AtomicBool>) {
// Set up the exporter to collect metrics
let _exporter = global_metrics_exporter();

Expand All @@ -139,6 +141,7 @@ pub async fn handle_serve_metrics(host: String, port: u16) {

server
.serve(app.into_make_service())
// .with_graceful_shutdown(shutdown_signal(running_program))
.await
.expect("Error starting example API server");
.expect("Error starting Prometheus metrics service");
}
6 changes: 5 additions & 1 deletion subgraph-radio/src/operator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ impl RadioOperator {
// Set up Prometheus metrics url if configured
if let Some(port) = self.config.metrics_port {
debug!("Initializing metrics port");
tokio::spawn(handle_serve_metrics(self.config.metrics_host.clone(), port));
tokio::spawn(handle_serve_metrics(
self.config.metrics_host.clone(),
port,
self.control_flow.running.clone(),
));
}

// Provide generated topics to Graphcast agent
Expand Down
9 changes: 4 additions & 5 deletions subgraph-radio/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::{
model::{build_schema, SubgraphRadioContext},
routes::{graphql_handler, graphql_playground, health},
},
shutdown_signal,
state::PersistedState,
};

Expand All @@ -25,7 +24,7 @@ pub mod routes;
pub async fn run_server(
config: Config,
persisted_state: &'static PersistedState,
running_program: Arc<AtomicBool>,
_running_program: Arc<AtomicBool>,
) {
if config.server_port().is_none() {
return;
Expand All @@ -50,11 +49,11 @@ pub async fn run_server(

info!(
host = tracing::field::debug(config.server_host()),
port, "Bind and serve"
port, "Bind port to service"
);
Server::bind(&addr)
.serve(app.into_make_service())
.with_graceful_shutdown(shutdown_signal(running_program))
// .with_graceful_shutdown(shutdown_signal(running_program))
.await
.unwrap();
.expect("Error starting API service");
}

0 comments on commit 6c699b3

Please sign in to comment.