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
feat: generating request id for every retry in consumer workflow (#10919)
gopikrishna000d9c242e8ec19
diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rsindex 7a663b5391..48f00aa0db 100644--- a/crates/router/src/routes/app.rs+++ b/crates/router/src/routes/app.rs@@ -153,6 +153,14 @@ impl scheduler::SchedulerSessionState for SessionState {fn get_application_source(&self) -> common_enums::ApplicationSource {self.conf.application_source}+ fn get_request_id(&self) -> Option<RequestId> {+ self.request_id.clone()+ }+ fn add_request_id(&mut self, request_id: RequestId) {+ self.api_client.add_request_id(request_id.clone());+ self.store.add_request_id(request_id.to_string());+ self.request_id.replace(request_id);+ }}impl SessionState {pub fn set_store(&mut self, store: Box<dyn StorageInterface>) {diff --git a/crates/scheduler/src/consumer.rs b/crates/scheduler/src/consumer.rsindex a938b8bd5b..97d7ea3f70 100644--- a/crates/scheduler/src/consumer.rs+++ b/crates/scheduler/src/consumer.rs@@ -230,7 +230,7 @@ pub async fn fetch_consumer_tasks(// Accept flow_options if required#[instrument(skip(state), fields(workflow_id))]pub async fn start_workflow<T>(- state: T,+ mut state: T,process: storage::ProcessTracker,_pickup_time: PrimitiveDateTime,workflow_selector: impl workflows::ProcessTrackerWorkflows<T> + 'static + std::fmt::Debug,@@ -238,10 +238,25 @@ pub async fn start_workflow<T>(whereT: SchedulerSessionState,{- tracing::Span::current().record("workflow_id", Uuid::new_v4().to_string());+ let workflow_id = Uuid::now_v7();+ tracing::Span::current().record("workflow_id", workflow_id.to_string());logger::info!(pt.name=?process.name, pt.id=%process.id);++ // Generate a unique request_id for this workflow execution if not already present+ if state.get_request_id().is_none() {+ match router_env::RequestId::try_from(workflow_id.to_string()) {+ Ok(req_id) => {+ logger::info!(workflow_request_id = %req_id, process_tracker_id = %process.id, "Generated request ID for workflow execution");+ state.add_request_id(req_id);+ }+ Err(err) => {+ logger::error!(error = %err, workflow_id = %workflow_id, "Failed to generate RequestId from workflow_id");+ }+ }+ }+let res = workflow_selector- .trigger_workflow(&state.clone(), process.clone())+ .trigger_workflow(&state, process.clone()).await.inspect_err(|error| {logger::error!(?error, "Failed to trigger workflow");diff --git a/crates/scheduler/src/scheduler.rs b/crates/scheduler/src/scheduler.rsindex 35c03aa4d4..76b1384ac3 100644--- a/crates/scheduler/src/scheduler.rs+++ b/crates/scheduler/src/scheduler.rs@@ -58,6 +58,8 @@ pub trait SchedulerAppState: Send + Sync + Clone {pub trait SchedulerSessionState: Send + Sync + Clone {fn get_application_source(&self) -> diesel_models::enums::ApplicationSource;fn get_db(&self) -> Box<dyn SchedulerInterface>;+ fn get_request_id(&self) -> Option<router_env::RequestId>;+ fn add_request_id(&mut self, request_id: router_env::RequestId);}pub async fn start_process_tracker<T: SchedulerAppState + 'static,