Skip to content

Commit f375913

Browse files
authored
Adjust some values in tax-related tasks (#4598)
* Adjust some values for tax processing * chore: query cache, clippy, fmt
1 parent a4015d9 commit f375913

File tree

3 files changed

+6
-14
lines changed

3 files changed

+6
-14
lines changed
Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/labrinth/src/database/models/charge_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ impl DBCharge {
338338
AND COALESCE(tax_last_updated, '-infinity' :: TIMESTAMPTZ) < NOW() - INTERVAL '1 day'
339339
AND u.email IS NOT NULL
340340
AND due - INTERVAL '7 days' > NOW()
341-
AND due - INTERVAL '14 days' < NOW() -- Due between 7 and 14 days from now
341+
AND due - INTERVAL '30 days' < NOW() -- Due between 7 and 30 days from now
342342
ORDER BY COALESCE(tax_last_updated, '-infinity' :: TIMESTAMPTZ) ASC
343343
FOR NO KEY UPDATE SKIP LOCKED
344344
LIMIT $1

apps/labrinth/src/queue/billing.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,19 @@ use tracing::{debug, error, info, warn};
3535

3636
/// Updates charges which need to have their tax amount updated. This is done within a timer to avoid reaching
3737
/// Anrok API limits.
38-
///
39-
/// The global rate limit for Anrok API operations is 10 RPS, so we run ~8 requests every second up
40-
/// to the specified limit of processed charges.
4138
async fn update_tax_amounts(
4239
pg: &PgPool,
4340
redis: &RedisPool,
4441
anrok_client: &anrok::Client,
4542
stripe_client: &stripe::Client,
4643
limit: i64,
4744
) -> Result<(), ApiError> {
48-
let mut interval = tokio::time::interval(std::time::Duration::from_secs(1));
49-
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
50-
5145
let mut processed_charges = 0;
5246

5347
loop {
54-
interval.tick().await;
55-
5648
let mut txn = pg.begin().await?;
5749

58-
let charges = DBCharge::get_updateable_lock(&mut *txn, 8).await?;
50+
let charges = DBCharge::get_updateable_lock(&mut *txn, 5).await?;
5951

6052
if charges.is_empty() {
6153
info!("No more charges to process");
@@ -1023,14 +1015,14 @@ pub async fn index_subscriptions(
10231015
&redis,
10241016
&anrok_client,
10251017
&stripe_client,
1026-
1000,
1018+
500,
10271019
),
10281020
)
10291021
.await;
10301022

10311023
run_and_time(
10321024
"update_tax_amounts",
1033-
update_tax_amounts(&pool, &redis, &anrok_client, &stripe_client, 50),
1025+
update_tax_amounts(&pool, &redis, &anrok_client, &stripe_client, 500),
10341026
)
10351027
.await;
10361028

0 commit comments

Comments
 (0)