You've already forked AstralRinth
forked from didirus/AstralRinth
Move update_bank_balances to billing task, don't fail every provider if one fails (#4332)
This commit is contained in:
committed by
GitHub
parent
d23b925bb9
commit
bd918c7616
@@ -17,6 +17,7 @@ use sqlx::PgPool;
|
||||
use sqlx::postgres::PgQueryResult;
|
||||
use std::collections::HashMap;
|
||||
use tokio::sync::RwLock;
|
||||
use tracing::error;
|
||||
|
||||
pub struct PayoutsQueue {
|
||||
credential: RwLock<Option<PayPalCredentials>>,
|
||||
@@ -1078,12 +1079,23 @@ pub async fn insert_bank_balances(
|
||||
) -> Result<(), ApiError> {
|
||||
let mut transaction = pool.begin().await?;
|
||||
|
||||
let (paypal, brex, tremendous) = futures::future::try_join3(
|
||||
PayoutsQueue::get_paypal_balance(),
|
||||
PayoutsQueue::get_brex_balance(),
|
||||
payouts.get_tremendous_balance(),
|
||||
)
|
||||
.await?;
|
||||
let paypal = PayoutsQueue::get_paypal_balance()
|
||||
.await
|
||||
.inspect_err(|error| error!(%error, "Failure getting PayPal balance"))
|
||||
.ok();
|
||||
|
||||
let brex = PayoutsQueue::get_brex_balance()
|
||||
.await
|
||||
.inspect_err(|error| error!(%error, "Failure getting Brex balance"))
|
||||
.ok();
|
||||
|
||||
let tremendous = payouts
|
||||
.get_tremendous_balance()
|
||||
.await
|
||||
.inspect_err(
|
||||
|error| error!(%error, "Failure getting Tremendous balance"),
|
||||
)
|
||||
.ok();
|
||||
|
||||
let mut insert_account_types = Vec::new();
|
||||
let mut insert_amounts = Vec::new();
|
||||
@@ -1108,9 +1120,15 @@ pub async fn insert_bank_balances(
|
||||
}
|
||||
};
|
||||
|
||||
add_balance("paypal", paypal);
|
||||
add_balance("brex", brex);
|
||||
add_balance("tremendous", tremendous);
|
||||
if let Some(paypal) = paypal {
|
||||
add_balance("paypal", paypal);
|
||||
}
|
||||
if let Some(brex) = brex {
|
||||
add_balance("brex", brex);
|
||||
}
|
||||
if let Some(tremendous) = tremendous {
|
||||
add_balance("tremendous", tremendous);
|
||||
}
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
|
||||
Reference in New Issue
Block a user