Tweaks and fixes to background tasks (#4447)

* adjustments

* chore: query cache, clippy, fmt
This commit is contained in:
François-Xavier Talbot
2025-09-30 12:43:59 +01:00
committed by GitHub
parent 53c9699b46
commit 54747aa628
13 changed files with 59 additions and 42 deletions

View File

@@ -260,13 +260,15 @@ impl DBCharge {
let charge_type = ChargeType::Subscription.as_str();
let res = select_charges_with_predicate!(
r#"
INNER JOIN users_subscriptions us ON us.id = charges.subscription_id
WHERE
charge_type = $1 AND
charges.charge_type = $1 AND
(
(status = 'cancelled' AND due < NOW()) OR
(status = 'expiring' AND due < NOW()) OR
(status = 'failed' AND last_attempt < NOW() - INTERVAL '2 days')
(charges.status = 'cancelled' AND charges.due < NOW()) OR
(charges.status = 'expiring' AND charges.due < NOW()) OR
(charges.status = 'failed' AND charges.last_attempt < NOW() - INTERVAL '2 days')
)
AND us.status = 'provisioned'
"#,
charge_type
)
@@ -321,6 +323,7 @@ impl DBCharge {
AND COALESCE(tax_last_updated, '-infinity' :: TIMESTAMPTZ) < NOW() - INTERVAL '1 day'
AND u.email IS NOT NULL
AND due - INTERVAL '7 days' > NOW()
AND due - INTERVAL '14 days' < NOW() -- Due between 7 and 14 days from now
ORDER BY COALESCE(tax_last_updated, '-infinity' :: TIMESTAMPTZ) ASC
FOR NO KEY UPDATE SKIP LOCKED
LIMIT $1

View File

@@ -64,7 +64,7 @@ impl NotificationBuilder {
ids.notification_id,
ids.user_id,
ids.date_available,
COALESCE(SUM(pv.amount), 0.0) sum
FLOOR(COALESCE(SUM(pv.amount), 0.0) * 100) :: BIGINT sum -- Convert to cents
FROM UNNEST($1::bigint[], $2::bigint[], $3::timestamptz[]) AS ids(notification_id, user_id, date_available)
LEFT JOIN payouts_values pv ON pv.user_id = ids.user_id AND pv.date_available = ids.date_available
GROUP BY ids.user_id, ids.notification_id, ids.date_available
@@ -81,6 +81,7 @@ impl NotificationBuilder {
'amount', to_jsonb(sum)
) body
FROM period_payouts
WHERE sum > 0
",
&notification_ids[..],
&users_raw_ids[..],

View File

@@ -7,7 +7,8 @@ const TEMPLATES_NAMESPACE: &str = "notifications_templates";
const TEMPLATES_HTML_DATA_NAMESPACE: &str = "notifications_templates_html_data";
const HTML_DATA_CACHE_EXPIRY: i64 = 60 * 15; // 15 minutes
#[derive(Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NotificationTemplate {
pub id: i64,
pub channel: NotificationChannel,