You've already forked AstralRinth
forked from didirus/AstralRinth
Only Fire Slack Webhook Once a Day (#4368)
* Only send webhook once per day * pat clippy's back * damn query cache
This commit is contained in:
committed by
GitHub
parent
9361acb78e
commit
d8d9720495
@@ -1,8 +1,14 @@
|
|||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "\n INSERT INTO payout_sources_balance (account_type, amount, pending, recorded)\n SELECT * FROM UNNEST ($1::text[], $2::numeric[], $3::boolean[], $4::timestamptz[])\n ON CONFLICT (recorded, account_type, pending)\n DO UPDATE SET amount = EXCLUDED.amount\n ",
|
"query": "\n INSERT INTO payout_sources_balance (account_type, amount, pending, recorded)\n SELECT * FROM UNNEST ($1::text[], $2::numeric[], $3::boolean[], $4::timestamptz[])\n ON CONFLICT (recorded, account_type, pending)\n DO UPDATE SET amount = EXCLUDED.amount\n RETURNING xmax = 0 \"xmax!\"\n ",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [
|
||||||
|
{
|
||||||
|
"ordinal": 0,
|
||||||
|
"name": "xmax!",
|
||||||
|
"type_info": "Bool"
|
||||||
|
}
|
||||||
|
],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"Left": [
|
"Left": [
|
||||||
"TextArray",
|
"TextArray",
|
||||||
@@ -11,7 +17,9 @@
|
|||||||
"TimestamptzArray"
|
"TimestamptzArray"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": [
|
||||||
|
null
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"hash": "dbdf1cce30709c3e1066d0a9156e12ce9e4773e3678da6f10f459a26bd0f3931"
|
"hash": "212d808123a9b4c5d4e72f3f6bed1f0d11f0da5aa0c59385bbabd138d28cb154"
|
||||||
}
|
}
|
||||||
@@ -1094,25 +1094,6 @@ pub async fn insert_bank_balances_and_webhook(
|
|||||||
let brex_result = PayoutsQueue::get_brex_balance().await;
|
let brex_result = PayoutsQueue::get_brex_balance().await;
|
||||||
let tremendous_result = payouts.get_tremendous_balance().await;
|
let tremendous_result = payouts.get_tremendous_balance().await;
|
||||||
|
|
||||||
let paypal = check_balance_with_webhook(
|
|
||||||
"paypal",
|
|
||||||
"PAYPAL_BALANCE_ALERT_THRESHOLD",
|
|
||||||
paypal_result,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
let brex = check_balance_with_webhook(
|
|
||||||
"brex",
|
|
||||||
"BREX_BALANCE_ALERT_THRESHOLD",
|
|
||||||
brex_result,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
let tremendous = check_balance_with_webhook(
|
|
||||||
"tremendous",
|
|
||||||
"TREMENDOUS_BALANCE_ALERT_THRESHOLD",
|
|
||||||
tremendous_result,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let mut insert_account_types = Vec::new();
|
let mut insert_account_types = Vec::new();
|
||||||
let mut insert_amounts = Vec::new();
|
let mut insert_amounts = Vec::new();
|
||||||
let mut insert_pending = Vec::new();
|
let mut insert_pending = Vec::new();
|
||||||
@@ -1133,31 +1114,53 @@ pub async fn insert_bank_balances_and_webhook(
|
|||||||
insert_recorded.push(today);
|
insert_recorded.push(today);
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(paypal) = paypal {
|
if let Ok(Some(ref paypal)) = paypal_result {
|
||||||
add_balance("paypal", &paypal);
|
add_balance("paypal", paypal);
|
||||||
}
|
}
|
||||||
if let Some(brex) = brex {
|
if let Ok(Some(ref brex)) = brex_result {
|
||||||
add_balance("brex", &brex);
|
add_balance("brex", brex);
|
||||||
}
|
}
|
||||||
if let Some(tremendous) = tremendous {
|
if let Ok(Some(ref tremendous)) = tremendous_result {
|
||||||
add_balance("tremendous", &tremendous);
|
add_balance("tremendous", tremendous);
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlx::query!(
|
let inserted = sqlx::query_scalar!(
|
||||||
"
|
r#"
|
||||||
INSERT INTO payout_sources_balance (account_type, amount, pending, recorded)
|
INSERT INTO payout_sources_balance (account_type, amount, pending, recorded)
|
||||||
SELECT * FROM UNNEST ($1::text[], $2::numeric[], $3::boolean[], $4::timestamptz[])
|
SELECT * FROM UNNEST ($1::text[], $2::numeric[], $3::boolean[], $4::timestamptz[])
|
||||||
ON CONFLICT (recorded, account_type, pending)
|
ON CONFLICT (recorded, account_type, pending)
|
||||||
DO UPDATE SET amount = EXCLUDED.amount
|
DO UPDATE SET amount = EXCLUDED.amount
|
||||||
",
|
RETURNING xmax = 0 "xmax!"
|
||||||
|
"#,
|
||||||
&insert_account_types[..],
|
&insert_account_types[..],
|
||||||
&insert_amounts[..],
|
&insert_amounts[..],
|
||||||
&insert_pending[..],
|
&insert_pending[..],
|
||||||
&insert_recorded[..],
|
&insert_recorded[..],
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.fetch_one(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
if inserted {
|
||||||
|
check_balance_with_webhook(
|
||||||
|
"paypal",
|
||||||
|
"PAYPAL_BALANCE_ALERT_THRESHOLD",
|
||||||
|
paypal_result,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
check_balance_with_webhook(
|
||||||
|
"brex",
|
||||||
|
"BREX_BALANCE_ALERT_THRESHOLD",
|
||||||
|
brex_result,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
check_balance_with_webhook(
|
||||||
|
"tremendous",
|
||||||
|
"TREMENDOUS_BALANCE_ALERT_THRESHOLD",
|
||||||
|
tremendous_result,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
transaction.commit().await?;
|
transaction.commit().await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user