Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(drainer): ignore errors in case the stream is empty (#2261)
Kartikeya Hegde53de86f60d14
diff --git a/crates/drainer/src/lib.rs b/crates/drainer/src/lib.rsindex 35ce4d2f87..c832c67c92 100644--- a/crates/drainer/src/lib.rs+++ b/crates/drainer/src/lib.rs@@ -119,8 +119,24 @@ async fn drainer(stream_name: &str,) -> errors::DrainerResult<()> {let stream_read =- utils::read_from_stream(stream_name, max_read_count, store.redis_conn.as_ref()).await?; // this returns the error.-+ match utils::read_from_stream(stream_name, max_read_count, store.redis_conn.as_ref()).await+ {+ Ok(result) => result,+ Err(error) => {+ if let errors::DrainerError::RedisError(redis_err) = error.current_context() {+ if let redis_interface::errors::RedisError::StreamEmptyOrNotAvailable =+ redis_err.current_context()+ {+ metrics::STREAM_EMPTY.add(&metrics::CONTEXT, 1, &[]);+ return Ok(());+ } else {+ return Err(error);+ }+ } else {+ return Err(error);+ }+ }+ };// parse_stream_entries returns error if no entries is found, handle itlet (entries, last_entry_id) = utils::parse_stream_entries(&stream_read, stream_name)?;let read_count = entries.len();diff --git a/crates/drainer/src/metrics.rs b/crates/drainer/src/metrics.rsindex 0839e8633c..77f3d5e7db 100644--- a/crates/drainer/src/metrics.rs+++ b/crates/drainer/src/metrics.rs@@ -11,6 +11,7 @@ counter_metric!(ERRORS_WHILE_QUERY_EXECUTION, DRAINER_METER);counter_metric!(SUCCESSFUL_QUERY_EXECUTION, DRAINER_METER);counter_metric!(SHUTDOWN_SIGNAL_RECEIVED, DRAINER_METER);counter_metric!(SUCCESSFUL_SHUTDOWN, DRAINER_METER);+counter_metric!(STREAM_EMPTY, DRAINER_METER);counter_metric!(DRAINER_HEALTH, DRAINER_METER);histogram_metric!(QUERY_EXECUTION_TIME, DRAINER_METER); // Time in (ms) millisecondsdiff --git a/crates/drainer/src/utils.rs b/crates/drainer/src/utils.rsindex 960ee5eca5..5a995652bb 100644--- a/crates/drainer/src/utils.rs+++ b/crates/drainer/src/utils.rs@@ -36,12 +36,11 @@ pub async fn read_from_stream(// "0-0" id gives first entrylet stream_id = "0-0";let (output, execution_time) = common_utils::date_time::time_it(|| async {- let entries = redis+ redis.stream_read_entries(stream_name, stream_id, Some(max_read_count)).await.map_err(DrainerError::from)- .into_report()?;- Ok(entries)+ .into_report()}).await;diff --git a/crates/redis_interface/src/commands.rs b/crates/redis_interface/src/commands.rsindex 413dee4ded..939586116f 100644--- a/crates/redis_interface/src/commands.rs+++ b/crates/redis_interface/src/commands.rs@@ -16,6 +16,7 @@ use common_utils::{use error_stack::{IntoReport, ResultExt};use fred::{interfaces::{HashesInterface, KeysInterface, StreamsInterface},+ prelude::RedisErrorKind,types::{Expiration, FromRedis, MultipleIDs, MultipleKeys, MultipleOrderedPairs, MultipleStrings,RedisKey, RedisMap, RedisValue, Scanner, SetOptions, XCap, XReadResponse,@@ -539,7 +540,12 @@ impl super::RedisConnectionPool {).await.into_report()- .change_context(errors::RedisError::StreamReadFailed)+ .map_err(|err| match err.current_context().kind() {+ RedisErrorKind::NotFound => {+ err.change_context(errors::RedisError::StreamEmptyOrNotAvailable)+ }+ _ => err.change_context(errors::RedisError::StreamReadFailed),+ })}#[instrument(level = "DEBUG", skip(self))]diff --git a/crates/redis_interface/src/errors.rs b/crates/redis_interface/src/errors.rsindex fa11874e60..4ea88638ac 100644--- a/crates/redis_interface/src/errors.rs+++ b/crates/redis_interface/src/errors.rs@@ -28,6 +28,8 @@ pub enum RedisError {StreamTrimFailed,#[error("Failed to acknowledge Redis stream entry")]StreamAcknowledgeFailed,+ #[error("Stream is either empty or not available")]+ StreamEmptyOrNotAvailable,#[error("Failed to create Redis consumer group")]ConsumerGroupCreateFailed,#[error("Failed to destroy Redis consumer group")]