deps(common_utils): put the signals module behind a feature flag (#814)

This commit is contained in:
ItsMeShashank
2023-04-04 11:29:05 +05:30
committed by GitHub
parent 6f61f83066
commit fb4ec43157
6 changed files with 22 additions and 35 deletions

View File

@ -7,6 +7,17 @@ rust-version = "1.65"
readme = "README.md" readme = "README.md"
license = "Apache-2.0" license = "Apache-2.0"
[features]
signals = [
"dep:signal-hook-tokio",
"dep:signal-hook",
"dep:tokio",
"dep:router_env"
]
logs = [
"dep:router_env"
]
[dependencies] [dependencies]
async-trait = "0.1.66" async-trait = "0.1.66"
bytes = "1.4.0" bytes = "1.4.0"
@ -21,16 +32,16 @@ ring = "0.16.20"
serde = { version = "1.0.155", features = ["derive"] } serde = { version = "1.0.155", features = ["derive"] }
serde_json = "1.0.94" serde_json = "1.0.94"
serde_urlencoded = "0.7.1" serde_urlencoded = "0.7.1"
signal-hook-tokio = { version = "0.3.1", features = ["futures-v0_3"] } signal-hook-tokio = { version = "0.3.1", features = ["futures-v0_3"], optional = true }
signal-hook = "0.3.15" signal-hook = { version = "0.3.15", optional = true }
tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"], optional = true }
thiserror = "1.0.39" thiserror = "1.0.39"
time = { version = "0.3.20", features = ["serde", "serde-well-known", "std"] } time = { version = "0.3.20", features = ["serde", "serde-well-known", "std"] }
md5 = "0.7.0" md5 = "0.7.0"
# First party crates # First party crates
masking = { version = "0.1.0", path = "../masking" } masking = { version = "0.1.0", path = "../masking" }
router_env = { version = "0.1.0", path = "../router_env", features = ["log_extra_implicit_fields", "log_custom_entries_to_extra"] } router_env = { version = "0.1.0", path = "../router_env", features = ["log_extra_implicit_fields", "log_custom_entries_to_extra"], optional = true }
[dev-dependencies] [dev-dependencies]
fake = "2.5.0" fake = "2.5.0"

View File

@ -9,6 +9,7 @@ pub mod errors;
pub mod ext_traits; pub mod ext_traits;
pub mod fp_utils; pub mod fp_utils;
pub mod pii; pub mod pii;
#[cfg(feature = "signals")]
pub mod signals; pub mod signals;
pub mod validation; pub mod validation;

View File

@ -3,6 +3,7 @@
use error_stack::report; use error_stack::report;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use regex::Regex; use regex::Regex;
#[cfg(feature = "logs")]
use router_env::logger; use router_env::logger;
use crate::errors::{CustomResult, ValidationError}; use crate::errors::{CustomResult, ValidationError};
@ -15,8 +16,9 @@ pub fn validate_email(email: &str) -> CustomResult<(), ValidationError> {
r"^(?i)[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$", r"^(?i)[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$",
) { ) {
Ok(regex) => Some(regex), Ok(regex) => Some(regex),
Err(error) => { Err(_error) => {
logger::error!(?error); #[cfg(feature = "logs")]
logger::error!(?_error);
None None
} }
} }

View File

@ -26,7 +26,7 @@ thiserror = "1.0.39"
tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] } tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] }
# First Party Crates # First Party Crates
common_utils = { version = "0.1.0", path = "../common_utils" } common_utils = { version = "0.1.0", path = "../common_utils", features = ["signals"] }
external_services = { version = "0.1.0", path = "../external_services" } external_services = { version = "0.1.0", path = "../external_services" }
redis_interface = { version = "0.1.0", path = "../redis_interface" } redis_interface = { version = "0.1.0", path = "../redis_interface" }
router_env = { version = "0.1.0", path = "../router_env", features = ["log_extra_implicit_fields", "log_custom_entries_to_extra"] } router_env = { version = "0.1.0", path = "../router_env", features = ["log_extra_implicit_fields", "log_custom_entries_to_extra"] }

View File

@ -80,7 +80,7 @@ uuid = { version = "1.3.0", features = ["serde", "v4"] }
# First party crates # First party crates
api_models = { version = "0.1.0", path = "../api_models", features = ["errors"] } api_models = { version = "0.1.0", path = "../api_models", features = ["errors"] }
common_utils = { version = "0.1.0", path = "../common_utils" } common_utils = { version = "0.1.0", path = "../common_utils", features = ["signals"] }
external_services = { version = "0.1.0", path = "../external_services" } external_services = { version = "0.1.0", path = "../external_services" }
masking = { version = "0.1.0", path = "../masking" } masking = { version = "0.1.0", path = "../masking" }
redis_interface = { version = "0.1.0", path = "../redis_interface" } redis_interface = { version = "0.1.0", path = "../redis_interface" }

View File

@ -4,10 +4,8 @@ use std::{
}; };
use error_stack::{report, ResultExt}; use error_stack::{report, ResultExt};
use futures::StreamExt;
use redis_interface::{RedisConnectionPool, RedisEntryId}; use redis_interface::{RedisConnectionPool, RedisEntryId};
use router_env::opentelemetry; use router_env::opentelemetry;
use tokio::sync::oneshot;
use uuid::Uuid; use uuid::Uuid;
use super::{consumer, metrics, process_data, workflows}; use super::{consumer, metrics, process_data, workflows};
@ -387,28 +385,3 @@ where
Ok(()) Ok(())
} }
} }
pub(crate) async fn signal_handler(
mut sig: signal_hook_tokio::Signals,
sender: oneshot::Sender<()>,
) {
if let Some(signal) = sig.next().await {
logger::info!(
"Received signal: {:?}",
signal_hook::low_level::signal_name(signal)
);
match signal {
signal_hook::consts::SIGTERM | signal_hook::consts::SIGINT => match sender.send(()) {
Ok(_) => {
logger::info!("Request for force shutdown received")
}
Err(_) => {
logger::error!(
"The receiver is closed, a termination call might already be sent"
)
}
},
_ => {}
}
}
}