Skip to content

Commit 4706db5

Browse files
authored
opus's fix for idle txn (#383)
1 parent 30bb70c commit 4706db5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/billing/src/grant-credits.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,25 +397,27 @@ export async function triggerMonthlyResetAndGrant(params: {
397397
.set({ next_quota_reset: newResetDate })
398398
.where(eq(schema.user.id, userId))
399399

400-
// Always grant free credits
401-
await processAndGrantCredit({
400+
// Always grant free credits - use grantCreditOperation with tx to keep everything in the same transaction
401+
await grantCreditOperation({
402402
...params,
403403
amount: freeGrantAmount,
404404
type: 'free',
405405
description: 'Monthly free credits',
406406
expiresAt: newResetDate, // Free credits expire at next reset
407407
operationId: freeOperationId,
408+
tx,
408409
})
409410

410411
// Only grant referral credits if there are any
411412
if (referralBonus > 0) {
412-
await processAndGrantCredit({
413+
await grantCreditOperation({
413414
...params,
414415
amount: referralBonus,
415416
type: 'referral',
416417
description: 'Monthly referral bonus',
417418
expiresAt: newResetDate, // Referral credits expire at next reset
418419
operationId: referralOperationId,
420+
tx,
419421
})
420422
}
421423

0 commit comments

Comments
 (0)