@@ -2,7 +2,7 @@ import { db } from '@sim/db'
22import { member , organization , subscription , userStats } from '@sim/db/schema'
33import { createLogger } from '@sim/logger'
44import { and , eq , sql } from 'drizzle-orm'
5- import { DEFAULT_OVERAGE_THRESHOLD } from '@/lib/billing/constants'
5+ import { BILLING_LOCK_TIMEOUT_MS , DEFAULT_OVERAGE_THRESHOLD } from '@/lib/billing/constants'
66import { getEffectiveBillingStatus , isOrganizationBillingBlocked } from '@/lib/billing/core/access'
77import { calculateSubscriptionOverage , computeOrgOverageAmount } from '@/lib/billing/core/billing'
88import {
@@ -22,7 +22,6 @@ import { enqueueOutboxEvent } from '@/lib/core/outbox/service'
2222const logger = createLogger ( 'ThresholdBilling' )
2323
2424const OVERAGE_THRESHOLD = envNumber ( env . OVERAGE_THRESHOLD_DOLLARS , DEFAULT_OVERAGE_THRESHOLD )
25- const USER_STATS_LOCK_TIMEOUT_MS = 5_000
2625const USAGE_TOTAL_EPSILON = 0.000001
2726
2827interface PersonalUsageSnapshot {
@@ -119,7 +118,7 @@ export async function checkAndBillOverageThreshold(userId: string): Promise<void
119118 const totalOverageCents = Math . round ( currentOverage * 100 )
120119
121120 await db . transaction ( async ( tx ) => {
122- await tx . execute ( sql . raw ( `SET LOCAL lock_timeout = '${ USER_STATS_LOCK_TIMEOUT_MS } ms'` ) )
121+ await tx . execute ( sql . raw ( `SET LOCAL lock_timeout = '${ BILLING_LOCK_TIMEOUT_MS } ms'` ) )
123122
124123 const statsRecords = await tx
125124 . select ( )
@@ -363,7 +362,7 @@ async function checkAndBillOrganizationOverageThreshold(organizationId: string):
363362 const totalOverageCents = Math . round ( currentOverage * 100 )
364363
365364 await db . transaction ( async ( tx ) => {
366- await tx . execute ( sql . raw ( `SET LOCAL lock_timeout = '${ USER_STATS_LOCK_TIMEOUT_MS } ms'` ) )
365+ await tx . execute ( sql . raw ( `SET LOCAL lock_timeout = '${ BILLING_LOCK_TIMEOUT_MS } ms'` ) )
367366
368367 const lockedOwnerRows = await tx
369368 . select ( { userId : member . userId } )
0 commit comments