Skip to content

Commit d634fde

Browse files
jarnuragithub-actions[bot]akshay-97akshay.sdracarys18
authored
feat: change async-bb8 fork and tokio spawn for concurrent database calls (#2774)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: akshay-97 <[email protected]> Co-authored-by: akshay.s <[email protected]> Co-authored-by: Kartikeya Hegde <[email protected]>
1 parent 496245d commit d634fde

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1512
-717
lines changed

Cargo.lock

Lines changed: 641 additions & 179 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/common_utils/src/types.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ impl<const PRECISION: u8> Percentage<PRECISION> {
7777
if value.contains('.') {
7878
// if string has '.' then take the decimal part and verify precision length
7979
match value.split('.').last() {
80-
Some(decimal_part) => decimal_part.trim_end_matches('0').len() <= PRECISION.into(),
80+
Some(decimal_part) => {
81+
decimal_part.trim_end_matches('0').len() <= <u8 as Into<usize>>::into(PRECISION)
82+
}
8183
// will never be None
8284
None => false,
8385
}

crates/diesel_models/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ default = ["kv_store"]
1212
kv_store = []
1313

1414
[dependencies]
15-
async-bb8-diesel = "0.1.0"
15+
async-bb8-diesel = { git = "https://github.com/jarnura/async-bb8-diesel", rev = "53b4ab901aab7635c8215fd1c2d542c8db443094" }
1616
diesel = { version = "2.1.0", features = ["postgres", "serde_json", "time", "64-column-tables"] }
1717
error-stack = "0.3.1"
1818
frunk = "0.4.1"

crates/drainer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ kms = ["external_services/kms"]
1313
vergen = ["router_env/vergen"]
1414

1515
[dependencies]
16-
async-bb8-diesel = "0.1.0"
16+
async-bb8-diesel = { git = "https://github.com/jarnura/async-bb8-diesel", rev = "53b4ab901aab7635c8215fd1c2d542c8db443094" }
1717
bb8 = "0.8"
1818
clap = { version = "4.3.2", default-features = false, features = ["std", "derive", "help", "usage"] }
1919
config = { version = "0.13.3", features = ["toml"] }

crates/router/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ actix-cors = "0.6.4"
3737
actix-multipart = "0.6.0"
3838
actix-rt = "2.8.0"
3939
actix-web = "4.3.1"
40+
async-bb8-diesel = { git = "https://github.com/jarnura/async-bb8-diesel", rev = "53b4ab901aab7635c8215fd1c2d542c8db443094" }
4041
argon2 = { version = "0.5.0", features = ["std"] }
41-
async-bb8-diesel = "0.1.0"
4242
async-trait = "0.1.68"
4343
aws-config = { version = "0.55.3", optional = true }
4444
aws-sdk-s3 = { version = "0.28.0", optional = true }
@@ -97,6 +97,7 @@ utoipa-swagger-ui = { version = "3.1.3", features = ["actix-web"] }
9797
uuid = { version = "1.3.3", features = ["serde", "v4"] }
9898
validator = "0.16.0"
9999
x509-parser = "0.15.0"
100+
tracing-futures = { version = "0.2.5", features = ["tokio"] }
100101

101102
# First party crates
102103
api_models = { version = "0.1.0", path = "../api_models", features = ["errors"] }

crates/router/src/bin/router.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use router::{
44
logger,
55
};
66

7-
#[actix_web::main]
7+
#[tokio::main]
88
async fn main() -> ApplicationResult<()> {
99
// get commandline config before initializing config
1010
let cmd_line = <CmdLineConf as clap::Parser>::parse();
@@ -43,7 +43,7 @@ async fn main() -> ApplicationResult<()> {
4343
logger::info!("Application started [{:?}] [{:?}]", conf.server, conf.log);
4444

4545
#[allow(clippy::expect_used)]
46-
let server = router::start_server(conf)
46+
let server = Box::pin(router::start_server(conf))
4747
.await
4848
.expect("Failed to create the server");
4949
let _ = server.await;

crates/router/src/bin/scheduler.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ async fn main() -> CustomResult<(), ProcessTrackerError> {
4040
);
4141
// channel for listening to redis disconnect events
4242
let (redis_shutdown_signal_tx, redis_shutdown_signal_rx) = oneshot::channel();
43-
let state = routes::AppState::new(conf, redis_shutdown_signal_tx, api_client).await;
43+
let state = Box::pin(routes::AppState::new(
44+
conf,
45+
redis_shutdown_signal_tx,
46+
api_client,
47+
))
48+
.await;
4449
// channel to shutdown scheduler gracefully
4550
let (tx, rx) = mpsc::channel(1);
4651
tokio::spawn(router::receiver_for_error(

crates/router/src/core/payment_methods/cards.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,7 +1944,14 @@ pub async fn do_list_customer_pm_fetch_customer_if_not_passed(
19441944
) -> errors::RouterResponse<api::CustomerPaymentMethodsListResponse> {
19451945
let db = state.store.as_ref();
19461946
if let Some(customer_id) = customer_id {
1947-
list_customer_payment_method(&state, merchant_account, key_store, None, customer_id).await
1947+
Box::pin(list_customer_payment_method(
1948+
&state,
1949+
merchant_account,
1950+
key_store,
1951+
None,
1952+
customer_id,
1953+
))
1954+
.await
19481955
} else {
19491956
let cloned_secret = req.and_then(|r| r.client_secret.as_ref().cloned());
19501957
let payment_intent = helpers::verify_payment_intent_time_and_client_secret(
@@ -1957,13 +1964,13 @@ pub async fn do_list_customer_pm_fetch_customer_if_not_passed(
19571964
.as_ref()
19581965
.and_then(|intent| intent.customer_id.to_owned())
19591966
.ok_or(errors::ApiErrorResponse::CustomerNotFound)?;
1960-
list_customer_payment_method(
1967+
Box::pin(list_customer_payment_method(
19611968
&state,
19621969
merchant_account,
19631970
key_store,
19641971
payment_intent,
19651972
&customer_id,
1966-
)
1973+
))
19671974
.await
19681975
}
19691976
}

crates/router/src/core/payments.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,15 @@ where
193193
)
194194
.await?;
195195
let operation = Box::new(PaymentResponse);
196-
let db = &*state.store;
196+
197197
connector_http_status_code = router_data.connector_http_status_code;
198198
external_latency = router_data.external_latency;
199199
//add connector http status code metrics
200200
add_connector_http_status_code_metrics(connector_http_status_code);
201201
operation
202202
.to_post_update_tracker()?
203203
.update_tracker(
204-
db,
204+
state,
205205
&validate_result.payment_id,
206206
payment_data,
207207
router_data,
@@ -272,15 +272,14 @@ where
272272
}
273273

274274
let operation = Box::new(PaymentResponse);
275-
let db = &*state.store;
276275
connector_http_status_code = router_data.connector_http_status_code;
277276
external_latency = router_data.external_latency;
278277
//add connector http status code metrics
279278
add_connector_http_status_code_metrics(connector_http_status_code);
280279
operation
281280
.to_post_update_tracker()?
282281
.update_tracker(
283-
db,
282+
state,
284283
&validate_result.payment_id,
285284
payment_data,
286285
router_data,
@@ -323,7 +322,7 @@ where
323322
(_, payment_data) = operation
324323
.to_update_tracker()?
325324
.update_trackers(
326-
&*state.store,
325+
state,
327326
payment_data.clone(),
328327
customer.clone(),
329328
validate_result.storage_scheme,
@@ -582,7 +581,14 @@ impl<Ctx: PaymentMethodRetrieve> PaymentRedirectFlow<Ctx> for PaymentRedirectCom
582581
}),
583582
..Default::default()
584583
};
585-
payments_core::<api::CompleteAuthorize, api::PaymentsResponse, _, _, _, Ctx>(
584+
Box::pin(payments_core::<
585+
api::CompleteAuthorize,
586+
api::PaymentsResponse,
587+
_,
588+
_,
589+
_,
590+
Ctx,
591+
>(
586592
state.clone(),
587593
merchant_account,
588594
merchant_key_store,
@@ -592,7 +598,7 @@ impl<Ctx: PaymentMethodRetrieve> PaymentRedirectFlow<Ctx> for PaymentRedirectCom
592598
connector_action,
593599
None,
594600
HeaderPayload::default(),
595-
)
601+
))
596602
.await
597603
}
598604

@@ -678,7 +684,14 @@ impl<Ctx: PaymentMethodRetrieve> PaymentRedirectFlow<Ctx> for PaymentRedirectSyn
678684
expand_attempts: None,
679685
expand_captures: None,
680686
};
681-
payments_core::<api::PSync, api::PaymentsResponse, _, _, _, Ctx>(
687+
Box::pin(payments_core::<
688+
api::PSync,
689+
api::PaymentsResponse,
690+
_,
691+
_,
692+
_,
693+
Ctx,
694+
>(
682695
state.clone(),
683696
merchant_account,
684697
merchant_key_store,
@@ -688,7 +701,7 @@ impl<Ctx: PaymentMethodRetrieve> PaymentRedirectFlow<Ctx> for PaymentRedirectSyn
688701
connector_action,
689702
None,
690703
HeaderPayload::default(),
691-
)
704+
))
692705
.await
693706
}
694707
fn generate_response(
@@ -889,7 +902,7 @@ where
889902
(_, *payment_data) = operation
890903
.to_update_tracker()?
891904
.update_trackers(
892-
&*state.store,
905+
state,
893906
payment_data.clone(),
894907
customer.clone(),
895908
merchant_account.storage_scheme,

crates/router/src/core/payments/flows/approve_flow.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,18 @@ impl
2525
customer: &Option<domain::Customer>,
2626
merchant_connector_account: &helpers::MerchantConnectorAccountType,
2727
) -> RouterResult<types::PaymentsApproveRouterData> {
28-
transformers::construct_payment_router_data::<api::Approve, types::PaymentsApproveData>(
28+
Box::pin(transformers::construct_payment_router_data::<
29+
api::Approve,
30+
types::PaymentsApproveData,
31+
>(
2932
state,
3033
self.clone(),
3134
connector_id,
3235
merchant_account,
3336
key_store,
3437
customer,
3538
merchant_connector_account,
36-
)
39+
))
3740
.await
3841
}
3942
}

0 commit comments

Comments
 (0)