Skip to content

Commit

Permalink
feat: add graceful shutdown to http indexer service
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannis committed Oct 26, 2023
1 parent e19a28f commit 82b954f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions common/src/indexer_service/http/indexer_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use reqwest::StatusCode;
use serde::{de::DeserializeOwned, Serialize};
use sqlx::postgres::PgPoolOptions;
use thiserror::Error;
use tokio::signal;
use toolshed::thegraph::DeploymentId;
use tracing::info;

Expand Down Expand Up @@ -297,3 +298,25 @@ impl IndexerService {
});
}
}

pub async fn shutdown_signal() {
let ctrl_c = async {
signal::ctrl_c()
.await
.expect("Failed to install Ctrl+C handler");
};

let terminate = async {
signal::unix::signal(signal::unix::SignalKind::terminate())
.expect("Failed to install signal handler")
.recv()
.await;
};

tokio::select! {
_ = ctrl_c => {},
_ = terminate => {},
}

info!("Signal received, starting graceful shutdown");
}

0 comments on commit 82b954f

Please sign in to comment.