Consider due expiring charge as unprovisionable

This commit is contained in:
fetch 2025-08-06 04:09:26 -04:00
parent 3f36a67bc8
commit c1fc072efe
No known key found for this signature in database
2 changed files with 6 additions and 1 deletions

View File

@ -240,6 +240,7 @@ impl DBCharge {
charge_type = $1 AND charge_type = $1 AND
( (
(status = 'cancelled' AND due < NOW()) OR (status = 'cancelled' AND due < NOW()) OR
(status = 'expiring' AND due < NOW()) OR
(status = 'failed' AND last_attempt < NOW() - INTERVAL '2 days') (status = 'failed' AND last_attempt < NOW() - INTERVAL '2 days')
) )
"#, "#,

View File

@ -2131,7 +2131,11 @@ pub async fn index_subscriptions(pool: PgPool, redis: RedisPool) {
let mut transaction = pool.begin().await?; let mut transaction = pool.begin().await?;
let mut clear_cache_users = Vec::new(); let mut clear_cache_users = Vec::new();
// If an active subscription has a canceled charge OR a failed charge more than two days ago, it should be cancelled // If an active subscription has:
// - A canceled charge due now
// - An expiring charge due now
// - A failed charge more than two days ago
// It should be unprovisioned.
let all_charges = DBCharge::get_unprovision(&pool).await?; let all_charges = DBCharge::get_unprovision(&pool).await?;
let mut all_subscriptions = let mut all_subscriptions =