Start graceful shutdown on SIGTERM
All checks were successful
Build and deploy / Build container and manifests (push) Successful in 5m32s
All checks were successful
Build and deploy / Build container and manifests (push) Successful in 5m32s
This commit is contained in:
parent
27f6119905
commit
878df8da40
17
src/main.rs
17
src/main.rs
|
@ -20,11 +20,28 @@ use tracing_subscriber::EnvFilter;
|
||||||
use tracing_subscriber::layer::SubscriberExt;
|
use tracing_subscriber::layer::SubscriberExt;
|
||||||
use tracing_subscriber::util::SubscriberInitExt;
|
use tracing_subscriber::util::SubscriberInitExt;
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
async fn sigterm() {
|
||||||
|
use tokio::signal::unix::SignalKind;
|
||||||
|
|
||||||
|
let mut sigterm =
|
||||||
|
tokio::signal::unix::signal(SignalKind::terminate()).expect("should be able to initialize");
|
||||||
|
sigterm.recv().await;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(unix))]
|
||||||
|
async fn sigterm() {
|
||||||
|
std::future::pending::<()>().await;
|
||||||
|
}
|
||||||
|
|
||||||
async fn shutdown_task(token: CancellationToken) {
|
async fn shutdown_task(token: CancellationToken) {
|
||||||
select! {
|
select! {
|
||||||
_ = tokio::signal::ctrl_c() => {
|
_ = tokio::signal::ctrl_c() => {
|
||||||
debug!("Received SIGINT");
|
debug!("Received SIGINT");
|
||||||
}
|
}
|
||||||
|
_ = sigterm() => {
|
||||||
|
debug!("Received SIGTERM");
|
||||||
|
}
|
||||||
_ = token.cancelled() => {
|
_ = token.cancelled() => {
|
||||||
debug!("Application called for graceful shutdown");
|
debug!("Application called for graceful shutdown");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user