text
stringlengths
70
351k
source
stringclasses
4 values
<|fim_prefix|> // file: hyperswitch/crates/diesel_models/src/query/file.rs | crate: diesel_models use diesel::{associations::HasTable, BoolExpressionMethods, ExpressionMethods}; use super::generics; use crate::{ errors, file::{FileMetadata, FileMetadataNew, FileMetadataUpdate, FileMetadataUpdateInternal}, schema::file_metadata::dsl, PgPooledConn, StorageResult, }; pub async fn update( self, conn: &PgPooledConn, file_metadata: FileMetadataUpdate, ) -> StorageResult<Self> { { Err(error) => match error.current_context() { errors::DatabaseError::NoFieldsToUpdate => Ok(self), _ => Err(error), },<|fim_suffix|> <|fim_middle|> result => result, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/diesel_models/src/query/file.rs | crate: diesel_models use diesel::{associations::HasTable, BoolExpressionMethods, ExpressionMethods}; use super::generics; use crate::{ errors, file::{FileMetadata, FileMetadataNew, FileMetadataUpdate, FileMetadataUpdateInternal}, schema::file_metadata::dsl, PgPooledConn, StorageResult, }; pub async fn update( self, conn: &PgPooledConn, file_metadata: FileMetadataUpdate, ) -> StorageResult<Self> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/diesel_models/src/query/file.rs | crate: diesel_models use diesel::{associations::HasTable, BoolExpressionMethods, ExpressionMethods}; use super::generics; use crate::{ errors, file::{FileMetadata, FileMetadataNew, FileMetadataUpdate, FileMetadataUpdateInternal}, schema::file_metadata::dsl, PgPooledConn, StorageResult, }; pub async fn delete_by_merchant_id_file_id( conn: &PgPooledConn, merchant_id: &common_utils::id_type::MerchantId, file_id: &str, ) -> StorageResult<bool> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/diesel_models/src/query/file.rs | crate: diesel_models use diesel::{associations::HasTable, BoolExpressionMethods, ExpressionMethods}; use super::generics; use crate::{ errors, file::{FileMetadata, FileMetadataNew, FileMetadataUpdate, FileMetadataUpdateInternal}, schema::file_metadata::dsl, PgPooledConn, StorageResult, }; pub async fn find_by_merchant_id_file_id( conn: &PgPooledConn, merchant_id: &common_utils::id_type::MerchantId, file_id: &str, ) -> StorageResult<Self> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/diesel_models/src/query/file.rs | crate: diesel_models use super::generics; use crate::{ errors, file::{FileMetadata, FileMetadataNew, FileMetadataUpdate, FileMetadataUpdateInternal}, schema::file_metadata::dsl, PgPooledConn, StorageResult, }; pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<FileMetadata> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/diesel_models/src/query/user/sample_data.rs | crate: diesel_models use diesel::{associations::HasTable, debug_query, ExpressionMethods, TextExpressionMethods}; use error_stack::ResultExt; use router_env::logger; use crate::schema::{ payment_attempt::dsl as payment_attempt_dsl, payment_intent::dsl as payment_intent_dsl, refund::dsl as refund_dsl, }; use crate::schema_v2::{ payment_attempt::dsl as payment_attempt_dsl, payment_intent::dsl as payment_intent_dsl, refund::dsl as refund_dsl, }; use crate::{ errors, schema::dispute::dsl as dispute_dsl, user, Dispute, DisputeNew, PaymentAttempt, PaymentIntent, PaymentIntentNew, PgPooledConn, Refund, RefundNew, StorageResult, }; pub async fn delete_refunds( conn: &PgPooledConn, merchant_id: &common_utils::id_type::MerchantId, ) -> StorageResult<Vec<Refund>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/diesel_models/src/query/user/sample_data.rs | crate: diesel_models use diesel::{associations::HasTable, debug_query, ExpressionMethods, TextExpressionMethods}; use error_stack::ResultExt; use router_env::logger; use crate::schema::{ payment_attempt::dsl as payment_attempt_dsl, payment_intent::dsl as payment_intent_dsl, refund::dsl as refund_dsl, }; use crate::schema_v2::{ payment_attempt::dsl as payment_attempt_dsl, payment_intent::dsl as payment_intent_dsl, refund::dsl as refund_dsl, }; use crate::{ errors, schema::dispute::dsl as dispute_dsl, user, Dispute, DisputeNew, PaymentAttempt, PaymentIntent, PaymentIntentNew, PgPooledConn, Refund, RefundNew, StorageResult, }; pub async fn delete_payment_intents( conn: &PgPooledConn, merchant_id: &common_utils::id_type::MerchantId, ) -> StorageResult<Vec<PaymentIntent>> { { n if n > 0 => { logger::debug!("{n} records deleted"); Ok(result) }<|fim_suffix|> <|fim_middle|> _ => Ok(result), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/diesel_models/src/query/user/sample_data.rs | crate: diesel_models use diesel::{associations::HasTable, debug_query, ExpressionMethods, TextExpressionMethods}; use error_stack::ResultExt; use router_env::logger; use crate::{ errors, schema::dispute::dsl as dispute_dsl, user, Dispute, DisputeNew, PaymentAttempt, PaymentIntent, PaymentIntentNew, PgPooledConn, Refund, RefundNew, StorageResult, }; pub async fn delete_disputes( conn: &PgPooledConn, merchant_id: &common_utils::id_type::MerchantId, ) -> StorageResult<Vec<Dispute>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/diesel_models/src/query/user/sample_data.rs | crate: diesel_models use diesel::{associations::HasTable, debug_query, ExpressionMethods, TextExpressionMethods}; use error_stack::ResultExt; use router_env::logger; use crate::schema::{ payment_attempt::dsl as payment_attempt_dsl, payment_intent::dsl as payment_intent_dsl, refund::dsl as refund_dsl, }; use crate::schema_v2::{ payment_attempt::dsl as payment_attempt_dsl, payment_intent::dsl as payment_intent_dsl, refund::dsl as refund_dsl, }; use crate::{ errors, schema::dispute::dsl as dispute_dsl, user, Dispute, DisputeNew, PaymentAttempt, PaymentIntent, PaymentIntentNew, PgPooledConn, Refund, RefundNew, StorageResult, }; pub async fn delete_refunds( conn: &PgPooledConn, merchant_id: &common_utils::id_type::MerchantId, ) -> StorageResult<Vec<Refund>> { let query = diesel::delete(<Refund>::table()) .filter(refund_dsl::merchant_id.eq(merchant_id.to_owned())) .filter(refund_dsl::payment_id.like("test_%")); logger::debug!(query = %debug_query::<diesel::pg::Pg,_>(&query).to_string()); query .get_results_async(conn) .await .change_context(errors::DatabaseError::Others) .attach_printable("Error while deleting refunds") .and_then(|result| match result.len() { n if n > 0 => { logger::debug!("{n} records deleted"); Ok(result) } 0 => Err(error_stack::report!(errors::DatabaseError::NotFound) .attach_printable("No records deleted")), _ => Ok(result), }) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/diesel_models/src/query/user/sample_data.rs | crate: diesel_models use diesel::{associations::HasTable, debug_query, ExpressionMethods, TextExpressionMethods}; use error_stack::ResultExt; use router_env::logger; use crate::schema::{ payment_attempt::dsl as payment_attempt_dsl, payment_intent::dsl as payment_intent_dsl, refund::dsl as refund_dsl, }; use crate::schema_v2::{ payment_attempt::dsl as payment_attempt_dsl, payment_intent::dsl as payment_intent_dsl, refund::dsl as refund_dsl, }; use crate::{ errors, schema::dispute::dsl as dispute_dsl, user, Dispute, DisputeNew, PaymentAttempt, PaymentIntent, PaymentIntentNew, PgPooledConn, Refund, RefundNew, StorageResult, }; pub async fn delete_payment_attempts( conn: &PgPooledConn, merchant_id: &common_utils::id_type::MerchantId, ) -> StorageResult<Vec<PaymentAttempt>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/diesel_models/src/query/user/sample_data.rs | crate: diesel_models use diesel::{associations::HasTable, debug_query, ExpressionMethods, TextExpressionMethods}; use error_stack::ResultExt; use router_env::logger; use crate::schema::{ payment_attempt::dsl as payment_attempt_dsl, payment_intent::dsl as payment_intent_dsl, refund::dsl as refund_dsl, }; use crate::schema_v2::{ payment_attempt::dsl as payment_attempt_dsl, payment_intent::dsl as payment_intent_dsl, refund::dsl as refund_dsl, }; use crate::{ errors, schema::dispute::dsl as dispute_dsl, user, Dispute, DisputeNew, PaymentAttempt, PaymentIntent, PaymentIntentNew, PgPooledConn, Refund, RefundNew, StorageResult, }; pub async fn delete_payment_intents( conn: &PgPooledConn, merchant_id: &common_utils::id_type::MerchantId, ) -> StorageResult<Vec<PaymentIntent>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/diesel_models/src/query/user/sample_data.rs | crate: diesel_models use diesel::{associations::HasTable, debug_query, ExpressionMethods, TextExpressionMethods}; use router_env::logger; use crate::{ errors, schema::dispute::dsl as dispute_dsl, user, Dispute, DisputeNew, PaymentAttempt, PaymentIntent, PaymentIntentNew, PgPooledConn, Refund, RefundNew, StorageResult, }; pub async fn insert_disputes( conn: &PgPooledConn, batch: Vec<DisputeNew>, ) -> StorageResult<Vec<Dispute>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/diesel_models/src/query/user/sample_data.rs | crate: diesel_models use diesel::{associations::HasTable, debug_query, ExpressionMethods, TextExpressionMethods}; use router_env::logger; use crate::{ errors, schema::dispute::dsl as dispute_dsl, user, Dispute, DisputeNew, PaymentAttempt, PaymentIntent, PaymentIntentNew, PgPooledConn, Refund, RefundNew, StorageResult, }; pub async fn insert_refunds( conn: &PgPooledConn, batch: Vec<RefundNew>, ) -> StorageResult<Vec<Refund>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/diesel_models/src/query/user/sample_data.rs | crate: diesel_models use diesel::{associations::HasTable, debug_query, ExpressionMethods, TextExpressionMethods}; use router_env::logger; use crate::{ errors, schema::dispute::dsl as dispute_dsl, user, Dispute, DisputeNew, PaymentAttempt, PaymentIntent, PaymentIntentNew, PgPooledConn, Refund, RefundNew, StorageResult, }; pub async fn insert_payment_attempts( conn: &PgPooledConn, batch: Vec<user::sample_data::PaymentAttemptBatchNew>, ) -> StorageResult<Vec<PaymentAttempt>> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/diesel_models/src/query/user/sample_data.rs | crate: diesel_models use diesel::{associations::HasTable, debug_query, ExpressionMethods, TextExpressionMethods}; use router_env::logger; use crate::{ errors, schema::dispute::dsl as dispute_dsl, user, Dispute, DisputeNew, PaymentAttempt, PaymentIntent, PaymentIntentNew, PgPooledConn, Refund, RefundNew, StorageResult, }; pub async fn insert_payment_intents( conn: &PgPooledConn, batch: Vec<PaymentIntentNew>, ) -> StorageResult<Vec<PaymentIntent>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/scheduler/src/scheduler.rs | crate: scheduler use std::sync::Arc; use common_utils::{errors::CustomResult, id_type}; use tokio::sync::mpsc; use super::env::logger::error; pub use crate::{ configs::settings::SchedulerSettings, consumer::{self, workflows}, db::{process_tracker::ProcessTrackerInterface, queue::QueueInterface}, errors, flow::SchedulerFlow, producer, }; pub type Store = RouterStore<StoreType>; pub type Store = KVRouterStore<StoreType>; pub async fn start_process_tracker< T: SchedulerAppState + 'static, U: SchedulerSessionState + 'static, F, >( state: &T, scheduler_flow: SchedulerFlow, scheduler_settings: Arc<SchedulerSettings>, channel: (mpsc::Sender<()>, mpsc::Receiver<()>), runner_from_task: impl workflows::ProcessTrackerWorkflows<U> + 'static + Copy + std::fmt::Debug, app_state_to_session_state: F, ) -> CustomResult<(), errors::ProcessTrackerError> where F: Fn(&T, &id_type::TenantId) -> CustomResult<U, errors::ProcessTrackerError>, { match scheduler_flow { SchedulerFlow::Producer => { producer::start_producer( state, scheduler_settings, channel, app_state_to_session_state, ) .await? } SchedulerFlow::Consumer => { consumer::start_consumer( state, scheduler_settings, runner_from_task, channel, app_state_to_session_state, ) .await? } SchedulerFlow::Cleaner => { error!("This flow has not been implemented yet!"); } } Ok(()) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/scheduler.rs | crate: scheduler use std::sync::Arc; use common_utils::{errors::CustomResult, id_type}; use tokio::sync::mpsc; use super::env::logger::error; pub use crate::{ configs::settings::SchedulerSettings, consumer::{self, workflows}, db::{process_tracker::ProcessTrackerInterface, queue::QueueInterface}, errors, flow::SchedulerFlow, producer, }; pub type Store = RouterStore<StoreType>; pub type Store = KVRouterStore<StoreType>; pub async fn start_process_tracker< T: SchedulerAppState + 'static, U: SchedulerSessionState + 'static, F, >( state: &T, scheduler_flow: SchedulerFlow, scheduler_settings: Arc<SchedulerSettings>, channel: (mpsc::Sender<()>, mpsc::Receiver<()>), runner_from_task: impl workflows::ProcessTrackerWorkflows<U> + 'static + Copy + std::fmt::Debug, app_state_to_session_state: F, ) -> CustomResult<(), errors::ProcessTrackerError> where F: Fn(&T, &id_type::TenantId) -> CustomResult<U, errors::ProcessTrackerError>, { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/scheduler.rs | crate: scheduler pub use crate::{ configs::settings::SchedulerSettings, consumer::{self, workflows}, db::{process_tracker::ProcessTrackerInterface, queue::QueueInterface}, errors, flow::SchedulerFlow, producer, }; fn as_scheduler(&self) -> &dyn SchedulerInterface { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/utils.rs | crate: scheduler fn test_get_delay() { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/utils.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models::process_tracker as storage; use crate::{ configs::settings::SchedulerSettings, consumer::types::ProcessTrackerBatch, errors, flow::SchedulerFlow, metrics, SchedulerInterface, SchedulerSessionState, }; pub(crate) async fn lock_acquire_release<T, F, Fut>( state: &T, settings: &SchedulerSettings, callback: F, ) -> CustomResult<(), errors::ProcessTrackerError> where F: Fn() -> Fut, T: SchedulerInterface + Send + Sync + ?Sized, Fut: futures::Future<Output = CustomResult<(), errors::ProcessTrackerError>>, { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/utils.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models::process_tracker as storage; use redis_interface::{RedisConnectionPool, RedisEntryId}; use super::{ consumer::{self, types::process_data, workflows}, env::logger, }; use crate::{ configs::settings::SchedulerSettings, consumer::types::ProcessTrackerBatch, errors, flow::SchedulerFlow, metrics, SchedulerInterface, SchedulerSessionState, }; pub async fn get_batches( conn: &RedisConnectionPool, stream_name: &str, group_name: &str, consumer_name: &str, ) -> CustomResult<Vec<ProcessTrackerBatch>, errors::ProcessTrackerError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/utils.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models::process_tracker as storage; use super::{ consumer::{self, types::process_data, workflows}, env::logger, }; pub fn get_pcr_payments_retry_schedule_time( mapping: process_data::RevenueRecoveryPaymentProcessTrackerMapping, merchant_id: &common_utils::id_type::MerchantId, retry_count: i32, ) -> Option<i32> { { Some(map) => map.clone(),<|fim_suffix|> <|fim_middle|> None => mapping.default_mapping, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/utils.rs | crate: scheduler use diesel_models::enums::{self, ProcessTrackerStatus}; pub use diesel_models::process_tracker as storage; use super::{ consumer::{self, types::process_data, workflows}, env::logger, }; pub fn get_pm_schedule_time( mapping: process_data::PaymentMethodsPTMapping, pm: enums::PaymentMethod, retry_count: i32, ) -> Option<i32> { { Some(map) => map.clone(),<|fim_suffix|> <|fim_middle|> None => mapping.default_mapping, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/utils.rs | crate: scheduler pub use diesel_models::process_tracker as storage; /// Get the delay based on the retry count pub fn get_delay<'a>( retry_count: i32, frequencies: impl IntoIterator<Item = &'a (i32, i32)>, ) -> Option<i32> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/utils.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models::process_tracker as storage; use super::{ consumer::{self, types::process_data, workflows}, env::logger, }; pub fn get_pcr_payments_retry_schedule_time( mapping: process_data::RevenueRecoveryPaymentProcessTrackerMapping, merchant_id: &common_utils::id_type::MerchantId, retry_count: i32, ) -> Option<i32> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/utils.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models::process_tracker as storage; use super::{ consumer::{self, types::process_data, workflows}, env::logger, }; pub fn get_outgoing_webhook_retry_schedule_time( mapping: process_data::OutgoingWebhookRetryProcessTrackerMapping, merchant_id: &common_utils::id_type::MerchantId, retry_count: i32, ) -> Option<i32> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/utils.rs | crate: scheduler use diesel_models::enums::{self, ProcessTrackerStatus}; pub use diesel_models::process_tracker as storage; use super::{ consumer::{self, types::process_data, workflows}, env::logger, }; pub fn get_pm_schedule_time( mapping: process_data::PaymentMethodsPTMapping, pm: enums::PaymentMethod, retry_count: i32, ) -> Option<i32> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/utils.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models::process_tracker as storage; use super::{ consumer::{self, types::process_data, workflows}, env::logger, }; pub fn get_schedule_time( mapping: process_data::ConnectorPTMapping, merchant_id: &common_utils::id_type::MerchantId, retry_count: i32, ) -> Option<i32> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/utils.rs | crate: scheduler pub use diesel_models::process_tracker as storage; use router_env::{instrument, tracing}; use super::{ consumer::{self, types::process_data, workflows}, env::logger, }; use crate::{ configs::settings::SchedulerSettings, consumer::types::ProcessTrackerBatch, errors, flow::SchedulerFlow, metrics, SchedulerInterface, SchedulerSessionState, }; pub fn add_histogram_metrics( pickup_time: &time::PrimitiveDateTime, task: &mut storage::ProcessTracker, stream_name: &str, ) { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/utils.rs | crate: scheduler use std::sync; use common_utils::errors::CustomResult; pub use diesel_models::process_tracker as storage; use error_stack::{report, ResultExt}; use super::{ consumer::{self, types::process_data, workflows}, env::logger, }; use crate::{ configs::settings::SchedulerSettings, consumer::types::ProcessTrackerBatch, errors, flow::SchedulerFlow, metrics, SchedulerInterface, SchedulerSessionState, }; pub async fn consumer_operation_handler<E, T>( state: T, settings: sync::Arc<SchedulerSettings>, error_handler_fun: E, workflow_selector: impl workflows::ProcessTrackerWorkflows<T> + 'static + Copy + std::fmt::Debug, ) where // Error handler function E: FnOnce(error_stack::Report<errors::ProcessTrackerError>), T: SchedulerSessionState + Send + Sync + 'static, { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/utils.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models::process_tracker as storage; pub fn get_time_from_delta(delta: Option<i32>) -> Option<time::PrimitiveDateTime> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/utils.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models::process_tracker as storage; pub fn get_process_tracker_id<'a>( runner: storage::ProcessTrackerRunner, task_name: &'a str, txn_id: &'a str, merchant_id: &'a common_utils::id_type::MerchantId, ) -> String { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/utils.rs | crate: scheduler pub use diesel_models::process_tracker as storage; use uuid::Uuid; use super::{ consumer::{self, types::process_data, workflows}, env::logger, }; use crate::{ configs::settings::SchedulerSettings, consumer::types::ProcessTrackerBatch, errors, flow::SchedulerFlow, metrics, SchedulerInterface, SchedulerSessionState, }; pub fn divide_into_batches( batch_size: usize, tasks: Vec<storage::ProcessTracker>, batch_creation_time: time::PrimitiveDateTime, conf: &SchedulerSettings, ) -> Vec<ProcessTrackerBatch> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/utils.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models::process_tracker as storage; use crate::{ configs::settings::SchedulerSettings, consumer::types::ProcessTrackerBatch, errors, flow::SchedulerFlow, metrics, SchedulerInterface, SchedulerSessionState, }; pub fn divide( tasks: Vec<storage::ProcessTracker>, conf: &SchedulerSettings, ) -> Vec<ProcessTrackerBatch> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/utils.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models::process_tracker as storage; use super::{ consumer::{self, types::process_data, workflows}, env::logger, }; use crate::{ configs::settings::SchedulerSettings, consumer::types::ProcessTrackerBatch, errors, flow::SchedulerFlow, metrics, SchedulerInterface, SchedulerSessionState, }; pub async fn divide_and_append_tasks<T>( state: &T, flow: SchedulerFlow, tasks: Vec<storage::ProcessTracker>, settings: &SchedulerSettings, ) -> CustomResult<(), errors::ProcessTrackerError> where T: SchedulerInterface + Send + Sync + ?Sized, { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/utils.rs | crate: scheduler use common_utils::errors::CustomResult; use diesel_models::enums::{self, ProcessTrackerStatus}; pub use diesel_models::process_tracker as storage; use error_stack::{report, ResultExt}; use redis_interface::{RedisConnectionPool, RedisEntryId}; use super::{ consumer::{self, types::process_data, workflows}, env::logger, }; use crate::{ configs::settings::SchedulerSettings, consumer::types::ProcessTrackerBatch, errors, flow::SchedulerFlow, metrics, SchedulerInterface, SchedulerSessionState, }; pub async fn update_status_and_append<T>( state: &T, flow: SchedulerFlow, pt_batch: ProcessTrackerBatch, ) -> CustomResult<(), errors::ProcessTrackerError> where T: SchedulerInterface + Send + Sync + ?Sized, { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/queue.rs | crate: scheduler use common_utils::errors::CustomResult; use redis_interface::{errors::RedisError, RedisEntryId, SetnxReply}; use storage_impl::{mock_db::MockDb, redis::kv_store::RedisConnInterface}; async fn consumer_group_create( &self, _stream: &str, _group: &str, _id: &RedisEntryId, ) -> CustomResult<(), RedisError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/queue.rs | crate: scheduler use common_utils::errors::CustomResult; use redis_interface::{errors::RedisError, RedisEntryId, SetnxReply}; async fn get_key(&self, _key: &str) -> CustomResult<Vec<u8>, RedisError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/queue.rs | crate: scheduler use common_utils::errors::CustomResult; use redis_interface::{errors::RedisError, RedisEntryId, SetnxReply}; use storage_impl::{mock_db::MockDb, redis::kv_store::RedisConnInterface}; async fn stream_append_entry( &self, _stream: &str, _entry_id: &RedisEntryId, _fields: Vec<(&str, String)>, ) -> CustomResult<(), RedisError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/queue.rs | crate: scheduler use common_utils::errors::CustomResult; use redis_interface::{errors::RedisError, RedisEntryId, SetnxReply}; use storage_impl::{mock_db::MockDb, redis::kv_store::RedisConnInterface}; async fn release_pt_lock(&self, _tag: &str, _lock_key: &str) -> CustomResult<bool, RedisError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/queue.rs | crate: scheduler use common_utils::errors::CustomResult; use redis_interface::{errors::RedisError, RedisEntryId, SetnxReply}; use storage_impl::{mock_db::MockDb, redis::kv_store::RedisConnInterface}; async fn acquire_pt_lock( &self, _tag: &str, _lock_key: &str, _lock_val: &str, _ttl: i64, ) -> CustomResult<bool, RedisError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/scheduler/src/db/queue.rs | crate: scheduler use common_utils::errors::CustomResult; use redis_interface::{errors::RedisError, RedisEntryId, SetnxReply}; use storage_impl::{mock_db::MockDb, redis::kv_store::RedisConnInterface}; async fn consumer_group_create( &self, _stream: &str, _group: &str, _id: &RedisEntryId, ) -> CustomResult<(), RedisError> { // [#172]: Implement function for `MockDb` Err(RedisError::ConsumerGroupCreateFailed)? }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/queue.rs | crate: scheduler use common_utils::errors::CustomResult; use diesel_models::process_tracker as storage; use storage_impl::{mock_db::MockDb, redis::kv_store::RedisConnInterface}; use crate::{errors::ProcessTrackerError, scheduler::Store}; async fn fetch_consumer_tasks( &self, _stream_name: &str, _group_name: &str, _consumer_name: &str, ) -> CustomResult<Vec<storage::ProcessTracker>, ProcessTrackerError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/queue.rs | crate: scheduler use common_utils::errors::CustomResult; use redis_interface::{errors::RedisError, RedisEntryId, SetnxReply}; async fn get_key(&self, key: &str) -> CustomResult<Vec<u8>, RedisError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/scheduler/src/db/queue.rs | crate: scheduler use common_utils::errors::CustomResult; use redis_interface::{errors::RedisError, RedisEntryId, SetnxReply}; async fn stream_append_entry( &self, stream: &str, entry_id: &RedisEntryId, fields: Vec<(&str, String)>, ) -> CustomResult<(), RedisError> { self.get_redis_conn()? .stream_append_entry(&stream.into(), entry_id, fields) .await }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/queue.rs | crate: scheduler use common_utils::errors::CustomResult; use redis_interface::{errors::RedisError, RedisEntryId, SetnxReply}; use router_env::logger; async fn release_pt_lock(&self, tag: &str, lock_key: &str) -> CustomResult<bool, RedisError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/queue.rs | crate: scheduler use common_utils::errors::CustomResult; use diesel_models::process_tracker as storage; use crate::{errors::ProcessTrackerError, scheduler::Store}; async fn fetch_consumer_tasks( &self, stream_name: &str, group_name: &str, consumer_name: &str, ) -> CustomResult<Vec<storage::ProcessTracker>, ProcessTrackerError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/process_tracker.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models as storage; use diesel_models::enums as storage_enums; use error_stack::{report, ResultExt}; use storage_impl::{connection, errors, mock_db::MockDb}; use time::PrimitiveDateTime; async fn find_processes_by_time_status( &self, time_lower_limit: PrimitiveDateTime, time_upper_limit: PrimitiveDateTime, status: storage_enums::ProcessTrackerStatus, limit: Option<i64>, ) -> CustomResult<Vec<storage::ProcessTracker>, errors::StorageError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/process_tracker.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models as storage; use storage_impl::{connection, errors, mock_db::MockDb}; async fn process_tracker_update_process_status_by_ids( &self, _task_ids: Vec<String>, _task_update: storage::ProcessTrackerUpdate, ) -> CustomResult<usize, errors::StorageError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/process_tracker.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models as storage; use storage_impl::{connection, errors, mock_db::MockDb}; async fn finish_process_with_business_status( &self, _this: storage::ProcessTracker, _business_status: &'static str, ) -> CustomResult<(), errors::StorageError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/process_tracker.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models as storage; use storage_impl::{connection, errors, mock_db::MockDb}; use time::PrimitiveDateTime; async fn retry_process( &self, _this: storage::ProcessTracker, _schedule_time: PrimitiveDateTime, ) -> CustomResult<(), errors::StorageError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/process_tracker.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models as storage; use storage_impl::{connection, errors, mock_db::MockDb}; use time::PrimitiveDateTime; async fn reset_process( &self, _this: storage::ProcessTracker, _schedule_time: PrimitiveDateTime, ) -> CustomResult<(), errors::StorageError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/process_tracker.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models as storage; use storage_impl::{connection, errors, mock_db::MockDb}; async fn update_process( &self, _this: storage::ProcessTracker, _process: storage::ProcessTrackerUpdate, ) -> CustomResult<storage::ProcessTracker, errors::StorageError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/process_tracker.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models as storage; use storage_impl::{connection, errors, mock_db::MockDb}; async fn insert_process( &self, new: storage::ProcessTrackerNew, ) -> CustomResult<storage::ProcessTracker, errors::StorageError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/process_tracker.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models as storage; use diesel_models::enums as storage_enums; use storage_impl::{connection, errors, mock_db::MockDb}; use time::PrimitiveDateTime; async fn find_processes_by_time_status( &self, _time_lower_limit: PrimitiveDateTime, _time_upper_limit: PrimitiveDateTime, _status: storage_enums::ProcessTrackerStatus, _limit: Option<i64>, ) -> CustomResult<Vec<storage::ProcessTracker>, errors::StorageError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/process_tracker.rs | crate: scheduler use common_utils::errors::CustomResult; use storage_impl::{connection, errors, mock_db::MockDb}; use time::PrimitiveDateTime; async fn reinitialize_limbo_processes( &self, _ids: Vec<String>, _schedule_time: PrimitiveDateTime, ) -> CustomResult<usize, errors::StorageError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/process_tracker.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models as storage; use error_stack::{report, ResultExt}; use storage_impl::{connection, errors, mock_db::MockDb}; async fn process_tracker_update_process_status_by_ids( &self, task_ids: Vec<String>, task_update: storage::ProcessTrackerUpdate, ) -> CustomResult<usize, errors::StorageError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/process_tracker.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models as storage; use diesel_models::enums as storage_enums; use storage_impl::{connection, errors, mock_db::MockDb}; use crate::{metrics, scheduler::Store}; async fn finish_process_with_business_status( &self, this: storage::ProcessTracker, business_status: &'static str, ) -> CustomResult<(), errors::StorageError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/process_tracker.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models as storage; use diesel_models::enums as storage_enums; use storage_impl::{connection, errors, mock_db::MockDb}; use time::PrimitiveDateTime; use crate::{metrics, scheduler::Store}; async fn retry_process( &self, this: storage::ProcessTracker, schedule_time: PrimitiveDateTime, ) -> CustomResult<(), errors::StorageError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/process_tracker.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models as storage; use diesel_models::enums as storage_enums; use storage_impl::{connection, errors, mock_db::MockDb}; use time::PrimitiveDateTime; async fn reset_process( &self, this: storage::ProcessTracker, schedule_time: PrimitiveDateTime, ) -> CustomResult<(), errors::StorageError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/process_tracker.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models as storage; use error_stack::{report, ResultExt}; use storage_impl::{connection, errors, mock_db::MockDb}; async fn update_process( &self, this: storage::ProcessTracker, process: storage::ProcessTrackerUpdate, ) -> CustomResult<storage::ProcessTracker, errors::StorageError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/scheduler/src/db/process_tracker.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models as storage; use error_stack::{report, ResultExt}; use storage_impl::{connection, errors, mock_db::MockDb}; async fn insert_process( &self, new: storage::ProcessTrackerNew, ) -> CustomResult<storage::ProcessTracker, errors::StorageError> { let conn = connection::pg_connection_write(self).await?; new.insert_process(&conn) .await .map_err(|error| report!(errors::StorageError::from(error))) }
ast_fragments
// file: hyperswitch/crates/scheduler/src/db/process_tracker.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models as storage; use diesel_models::enums as storage_enums; use error_stack::{report, ResultExt}; use storage_impl::{connection, errors, mock_db::MockDb}; use time::PrimitiveDateTime; async fn find_processes_by_time_status( &self, time_lower_limit: PrimitiveDateTime, time_upper_limit: PrimitiveDateTime, status: storage_enums::ProcessTrackerStatus, limit: Option<i64>, ) -> CustomResult<Vec<storage::ProcessTracker>, errors::StorageError> { let conn = connection::pg_connection_read(self).await?; storage::ProcessTracker::find_processes_by_time_status( &conn, time_lower_limit, time_upper_limit, status, limit, common_types::consts::API_VERSION, ) .await .map_err(|error| report!(errors::StorageError::from(error))) }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/db/process_tracker.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models as storage; use error_stack::{report, ResultExt}; use storage_impl::{connection, errors, mock_db::MockDb}; use time::PrimitiveDateTime; async fn reinitialize_limbo_processes( &self, ids: Vec<String>, schedule_time: PrimitiveDateTime, ) -> CustomResult<usize, errors::StorageError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/consumer/workflows.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models::process_tracker as storage; use diesel_models::process_tracker::business_status; use router_env::logger; use crate::{errors, SchedulerSessionState}; pub type WorkflowSelectorFn = fn(&storage::ProcessTracker) -> Result<(), errors::ProcessTrackerError>; async fn execute_workflow<'a>( &'a self, operation: Box<dyn ProcessTrackerWorkflow<T>>, state: &'a T, process: storage::ProcessTracker, ) -> CustomResult<(), errors::ProcessTrackerError> where T: SchedulerSessionState, { { Ok(_) => operation.success_handler(app_state, process).await,<|fim_suffix|> <|fim_middle|> Err(error) => match operation .error_handler(app_state, process.clone(), error) .await { Ok(_) => (), Err(error) => { logger::error!( ?error, "Failed to handle process tracker workflow execution error" ); let status = app_state .get_db() .as_scheduler() .finish_process_with_business_status( process, business_status::GLOBAL_FAILURE, ) .await; if let Err(error) = status { logger::error!(?error, "Failed to update process business status"); } } }, } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/consumer/workflows.rs | crate: scheduler pub use diesel_models::process_tracker as storage; pub type WorkflowSelectorFn = fn(&storage::ProcessTracker) -> Result<(), errors::ProcessTrackerError>; /// Callback function after successful execution of the `execute_workflow` async fn success_handler<'a>(&'a self, _state: &'a T, _process: storage::ProcessTracker) { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/consumer/workflows.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models::process_tracker as storage; use diesel_models::process_tracker::business_status; use router_env::logger; use crate::{errors, SchedulerSessionState}; pub type WorkflowSelectorFn = fn(&storage::ProcessTracker) -> Result<(), errors::ProcessTrackerError>; async fn execute_workflow<'a>( &'a self, operation: Box<dyn ProcessTrackerWorkflow<T>>, state: &'a T, process: storage::ProcessTracker, ) -> CustomResult<(), errors::ProcessTrackerError> where T: SchedulerSessionState, { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/consumer/workflows.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models::process_tracker as storage; use crate::{errors, SchedulerSessionState}; pub type WorkflowSelectorFn = fn(&storage::ProcessTracker) -> Result<(), errors::ProcessTrackerError>; /// Callback function after error received from `execute_workflow` async fn error_handler<'a>( &'a self, _state: &'a T, _process: storage::ProcessTracker, _error: errors::ProcessTrackerError, ) -> CustomResult<(), errors::ProcessTrackerError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
// file: hyperswitch/crates/scheduler/src/consumer/workflows.rs | crate: scheduler pub use diesel_models::process_tracker as storage; pub type WorkflowSelectorFn = fn(&storage::ProcessTracker) -> Result<(), errors::ProcessTrackerError>; /// Callback function after successful execution of the `execute_workflow` async fn success_handler<'a>(&'a self, _state: &'a T, _process: storage::ProcessTracker) {}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/consumer/workflows.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models::process_tracker as storage; use crate::{errors, SchedulerSessionState}; pub type WorkflowSelectorFn = fn(&storage::ProcessTracker) -> Result<(), errors::ProcessTrackerError>; /// The core execution of the workflow async fn execute_workflow<'a>( &'a self, _state: &'a T, _process: storage::ProcessTracker, ) -> Result<(), errors::ProcessTrackerError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/scheduler/src/consumer/workflows.rs | crate: scheduler use common_utils::errors::CustomResult; pub use diesel_models::process_tracker as storage; use crate::{errors, SchedulerSessionState}; pub type WorkflowSelectorFn = fn(&storage::ProcessTracker) -> Result<(), errors::ProcessTrackerError>; async fn trigger_workflow<'a>( &'a self, _state: &'a T, _process: storage::ProcessTracker, ) -> CustomResult<(), errors::ProcessTrackerError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/stream.rs | crate: drainer use redis_interface as redis; use router_env::{logger, tracing}; use crate::{errors, metrics, Store}; pub type StreamEntries = Vec<(String, HashMap<String, String>)>; pub type StreamReadResult = HashMap<String, StreamEntries>; pub async fn trim_from_stream( &self, stream_name: &str, minimum_entry_id: &str, ) -> errors::DrainerResult<usize> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/stream.rs | crate: drainer use redis_interface as redis; use router_env::{logger, tracing}; use crate::{errors, metrics, Store}; pub type StreamEntries = Vec<(String, HashMap<String, String>)>; pub type StreamReadResult = HashMap<String, StreamEntries>; pub async fn make_stream_available(&self, stream_name_flag: &str) -> errors::DrainerResult<()> { { Ok(redis::DelReply::KeyDeleted) => Ok(()),<|fim_suffix|> <|fim_middle|> Err(error) => Err(errors::DrainerError::from(error).into()), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/stream.rs | crate: drainer use redis_interface as redis; use router_env::{logger, tracing}; pub type StreamEntries = Vec<(String, HashMap<String, String>)>; pub type StreamReadResult = HashMap<String, StreamEntries>; pub async fn is_stream_available(&self, stream_index: u8) -> bool { { Ok(resp) => resp == redis::types::SetnxReply::KeySet,<|fim_suffix|> <|fim_middle|> Err(error) => { logger::error!(operation="lock_stream",err=?error); false } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/stream.rs | crate: drainer use router_env::{logger, tracing}; use crate::{errors, metrics, Store}; pub type StreamEntries = Vec<(String, HashMap<String, String>)>; pub type StreamReadResult = HashMap<String, StreamEntries>; pub async fn read_from_stream( &self, stream_name: &str, max_read_count: u64, ) -> errors::DrainerResult<StreamReadResult> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/stream.rs | crate: drainer use redis_interface as redis; use router_env::{logger, tracing}; use crate::{errors, metrics, Store}; pub type StreamEntries = Vec<(String, HashMap<String, String>)>; pub type StreamReadResult = HashMap<String, StreamEntries>; pub async fn make_stream_available(&self, stream_name_flag: &str) -> errors::DrainerResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/stream.rs | crate: drainer use redis_interface as redis; use router_env::{logger, tracing}; pub type StreamEntries = Vec<(String, HashMap<String, String>)>; pub type StreamReadResult = HashMap<String, StreamEntries>; pub async fn is_stream_available(&self, stream_index: u8) -> bool { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/stream.rs | crate: drainer use crate::{errors, metrics, Store}; pub type StreamEntries = Vec<(String, HashMap<String, String>)>; pub type StreamReadResult = HashMap<String, StreamEntries>; pub(crate) fn get_drainer_stream_name(&self, stream_index: u8) -> String { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/stream.rs | crate: drainer use crate::{errors, metrics, Store}; pub type StreamEntries = Vec<(String, HashMap<String, String>)>; pub type StreamReadResult = HashMap<String, StreamEntries>; pub(crate) fn get_stream_key_flag(&self, stream_index: u8) -> String { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/stream.rs | crate: drainer pub type StreamEntries = Vec<(String, HashMap<String, String>)>; pub type StreamReadResult = HashMap<String, StreamEntries>; pub fn drainer_stream(&self, shard_key: &str) -> String { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/handler.rs | crate: drainer use std::{ collections::HashMap, sync::{atomic, Arc}, }; use crate::{ errors, instrument, logger, metrics, query::ExecuteQuery, tracing, utils, DrainerSettings, Store, StreamData, }; async fn drainer_handler( store: Arc<Store>, stream_index: u8, max_read_count: u64, active_tasks: Arc<atomic::AtomicU64>, jobs_picked: Arc<atomic::AtomicU8>, ) -> errors::DrainerResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/handler.rs | crate: drainer use tokio::{ sync::{mpsc, oneshot}, time::{self, Duration}, }; use crate::{ errors, instrument, logger, metrics, query::ExecuteQuery, tracing, utils, DrainerSettings, Store, StreamData, }; pub fn spawn_error_handlers(&self, tx: mpsc::Sender<()>) -> errors::DrainerResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/handler.rs | crate: drainer use std::{ collections::HashMap, sync::{atomic, Arc}, }; use tokio::{ sync::{mpsc, oneshot}, time::{self, Duration}, }; use crate::{ errors, instrument, logger, metrics, query::ExecuteQuery, tracing, utils, DrainerSettings, Store, StreamData, }; pub async fn spawn(&self) -> errors::DrainerResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/handler.rs | crate: drainer use tokio::{ sync::{mpsc, oneshot}, time::{self, Duration}, }; use crate::{ errors, instrument, logger, metrics, query::ExecuteQuery, tracing, utils, DrainerSettings, Store, StreamData, }; pub async fn redis_error_receiver(rx: oneshot::Receiver<()>, shutdown_channel: mpsc::Sender<()>) { { Ok(_) => { logger::error!("The redis server failed"); let _ = shutdown_channel.send(()).await.map_err(|err| { logger::error!("Failed to send signal to the shutdown channel {err}") }); }<|fim_suffix|> <|fim_middle|> Err(err) => { logger::error!("Channel receiver error {err}"); } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/handler.rs | crate: drainer use tokio::{ sync::{mpsc, oneshot}, time::{self, Duration}, }; use crate::{ errors, instrument, logger, metrics, query::ExecuteQuery, tracing, utils, DrainerSettings, Store, StreamData, }; pub async fn redis_error_receiver(rx: oneshot::Receiver<()>, shutdown_channel: mpsc::Sender<()>) { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/handler.rs | crate: drainer use std::{ collections::HashMap, sync::{atomic, Arc}, }; use tokio::{ sync::{mpsc, oneshot}, time::{self, Duration}, }; use crate::{ errors, instrument, logger, metrics, query::ExecuteQuery, tracing, utils, DrainerSettings, Store, StreamData, }; pub(crate) async fn shutdown_listener(&self, mut rx: mpsc::Receiver<()>) { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/handler.rs | crate: drainer use std::{ collections::HashMap, sync::{atomic, Arc}, }; use tokio::{ sync::{mpsc, oneshot}, time::{self, Duration}, }; pub fn close(&self) { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/handler.rs | crate: drainer use std::{ collections::HashMap, sync::{atomic, Arc}, }; use common_utils::id_type; use tokio::{ sync::{mpsc, oneshot}, time::{self, Duration}, }; use crate::{ errors, instrument, logger, metrics, query::ExecuteQuery, tracing, utils, DrainerSettings, Store, StreamData, }; pub fn from_conf( conf: DrainerSettings, stores: HashMap<id_type::TenantId, Arc<Store>>, ) -> Self { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
// file: hyperswitch/crates/drainer/src/handler.rs | crate: drainer use tokio::{ sync::{mpsc, oneshot}, time::{self, Duration}, }; fn deref(&self) -> &Self::Target { &self.inner }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/handler.rs | crate: drainer use std::{ collections::HashMap, sync::{atomic, Arc}, }; use common_utils::id_type; use router_env::tracing::Instrument; use crate::{ errors, instrument, logger, metrics, query::ExecuteQuery, tracing, utils, DrainerSettings, Store, StreamData, }; async fn drainer( store: Arc<Store>, max_read_count: u64, stream_name: &str, jobs_picked: Arc<atomic::AtomicU8>, ) -> errors::DrainerResult<()> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/query.rs | crate: drainer use std::sync::Arc; use common_utils::errors::CustomResult; use diesel_models::errors::DatabaseError; use crate::{kv, logger, metrics, pg_connection, services::Store}; async fn execute_query( self, store: &Arc<Store>, pushed_at: i64, ) -> CustomResult<(), DatabaseError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/query.rs | crate: drainer use common_utils::errors::CustomResult; use crate::{kv, logger, metrics, pg_connection, services::Store}; fn push_drainer_delay( pushed_at: i64, operation: &str, table: &str, tags: &[router_env::opentelemetry::KeyValue], ) { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/query.rs | crate: drainer use std::sync::Arc; use common_utils::errors::CustomResult; use diesel_models::errors::DatabaseError; use crate::{kv, logger, metrics, pg_connection, services::Store}; async fn execute_query( self, store: &Arc<Store>, pushed_at: i64, ) -> CustomResult<(), DatabaseError> { { Ok(result) => { logger::info!(operation = operation, table = table, ?result); metrics::SUCCESSFUL_QUERY_EXECUTION.add(1, tags); Ok(()) }<|fim_suffix|> <|fim_middle|> Err(err) => { logger::error!(operation = operation, table = table, ?err); metrics::ERRORS_WHILE_QUERY_EXECUTION.add(1, tags); Err(err) } } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/query.rs | crate: drainer use common_utils::errors::CustomResult; use crate::{kv, logger, metrics, pg_connection, services::Store}; fn push_drainer_delay( pushed_at: i64, operation: &str, table: &str, tags: &[router_env::opentelemetry::KeyValue], ) { { Ok(delay) => metrics::DRAINER_DELAY_SECONDS.record(delay, tags),<|fim_suffix|> <|fim_middle|> Err(error) => logger::error!( pushed_at, drained_at, delay, ?error, "Invalid drainer delay" ), } }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/main.rs | crate: drainer use std::collections::HashMap; use drainer::{errors::DrainerResult, logger, services, settings, start_drainer, start_web_server}; use router_env::tracing::Instrument; async fn main() -> DrainerResult<()> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/main.rs | crate: drainer use std::collections::HashMap; use drainer::{errors::DrainerResult, logger, services, settings, start_drainer, start_web_server}; use router_env::tracing::Instrument; async fn main() -> DrainerResult<()> { {// Get configuration<|fim_suffix|> <|fim_middle|> Ok(())}}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/health_check.rs | crate: drainer use common_utils::{errors::CustomResult, id_type}; use error_stack::ResultExt; use router_env::{instrument, logger, tracing}; use crate::{ connection::pg_connection, errors::HealthCheckError, services::{self, log_and_return_error_response, Store}, Settings, }; async fn health_check_redis( &self, _conf: &Settings, ) -> CustomResult<(), HealthCheckRedisError> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/health_check.rs | crate: drainer use common_utils::{errors::CustomResult, id_type}; use diesel_models::{Config, ConfigNew}; use router_env::{instrument, logger, tracing}; use crate::{ connection::pg_connection, errors::HealthCheckError, services::{self, log_and_return_error_response, Store}, Settings, }; async fn health_check_db(&self) -> CustomResult<(), HealthCheckDBError> { {<|fim_suffix|> <|fim_middle|> }}
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/health_check.rs | crate: drainer use std::{collections::HashMap, sync::Arc}; use actix_web::{web, Scope}; use error_stack::ResultExt; use router_env::{instrument, logger, tracing}; use crate::{ connection::pg_connection, errors::HealthCheckError, services::{self, log_and_return_error_response, Store}, Settings, }; pub async fn deep_health_check_func( conf: web::Data<Settings>, store: &Arc<Store>, ) -> Result<DrainerHealthCheckResponse, error_stack::Report<HealthCheckError>> { <|fim_suffix|> <|fim_middle|> }
ast_fragments
<|fim_prefix|> // file: hyperswitch/crates/drainer/src/health_check.rs | crate: drainer use std::{collections::HashMap, sync::Arc}; use actix_web::{web, Scope}; use router_env::{instrument, logger, tracing}; use crate::{ connection::pg_connection, errors::HealthCheckError, services::{self, log_and_return_error_response, Store}, Settings, }; pub async fn deep_health_check( conf: web::Data<Settings>, stores: web::Data<HashMap<String, Arc<Store>>>, ) -> impl actix_web::Responder { <|fim_suffix|> <|fim_middle|> }
ast_fragments