From fede7893ca760acce4340432256dffd4e446127b Mon Sep 17 00:00:00 2001 From: Marie Date: Thu, 1 Dec 2022 20:14:07 +0000 Subject: [PATCH] Fix shutdown hook --- Cargo.lock | 7 +++++++ Cargo.toml | 4 +++- src/main.rs | 7 +++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b8d2bc6..8b36d59 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -371,6 +371,7 @@ checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0" dependencies = [ "futures-channel", "futures-core", + "futures-executor", "futures-io", "futures-sink", "futures-task", @@ -439,10 +440,13 @@ version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" dependencies = [ + "futures-channel", "futures-core", + "futures-io", "futures-macro", "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", "slab", @@ -1224,6 +1228,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "213241f76fb1e37e27de3b6aa1b068a2c333233b59cca6634f634b80a27ecf1e" dependencies = [ + "futures-core", "libc", "signal-hook", "tokio", @@ -1517,6 +1522,7 @@ dependencies = [ "cached", "chrono", "dotenvy", + "futures", "itertools", "lazy_static", "opentelemetry", @@ -1524,6 +1530,7 @@ dependencies = [ "prometheus", "reqwest", "serde", + "signal-hook", "signal-hook-tokio", "thiserror", "tokio", diff --git a/Cargo.toml b/Cargo.toml index 533fdba..b4718a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,9 @@ lazy_static = "1.4" cached = "0.40" [target.'cfg(unix)'.dependencies] -signal-hook-tokio = "0.3" +signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] } +signal-hook = "0.3" +futures = "0.3" [profile.release] lto = true diff --git a/src/main.rs b/src/main.rs index 7692e71..7fccc63 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,5 @@ use std::{ collections::hash_map::DefaultHasher, - future, hash::{Hash, Hasher}, }; @@ -21,6 +20,10 @@ use opentelemetry_prometheus::{PrometheusExporter, TextEncoder}; use reqwest::StatusCode; use traewelling_exporter::traewelling::client::TraewellingClient; +#[cfg(unix)] +use futures::stream::StreamExt; +#[cfg(unix)] +use signal_hook::consts::*; #[cfg(unix)] use signal_hook_tokio::Signals; @@ -85,7 +88,7 @@ async fn shutdown_signal() { #[cfg(unix)] async fn shutdown_signal() { - let signals = + let mut signals = Signals::new(&[SIGTERM, SIGINT, SIGQUIT]).expect("Failed to create signal handler"); signals.next().await;