1
1
import { BillingClient , SetPlanBody } from "@trigger.dev/billing" ;
2
- import { PrismaClient , prisma } from "~/db.server" ;
2
+ import { $replica , PrismaClient , PrismaReplicaClient , prisma } from "~/db.server" ;
3
3
import { env } from "~/env.server" ;
4
4
import { logger } from "~/services/logger.server" ;
5
5
import { organizationBillingPath } from "~/utils/pathBuilder" ;
6
6
7
7
export class BillingService {
8
8
#billingClient: BillingClient | undefined ;
9
9
#prismaClient: PrismaClient ;
10
+ #replica: PrismaReplicaClient ;
10
11
11
- constructor ( isManagedCloud : boolean , prismaClient : PrismaClient = prisma ) {
12
+ constructor ( isManagedCloud : boolean , prismaClient : PrismaClient = prisma , replica : PrismaReplicaClient = $replica ) {
12
13
this . #prismaClient = prismaClient ;
14
+ this . #replica = replica ;
13
15
if ( isManagedCloud && process . env . BILLING_API_URL && process . env . BILLING_API_KEY ) {
14
16
this . #billingClient = new BillingClient ( {
15
17
url : process . env . BILLING_API_URL ,
@@ -35,7 +37,7 @@ export class BillingService {
35
37
firstDayOfNextMonth . setMonth ( firstDayOfNextMonth . getMonth ( ) + 1 ) ;
36
38
firstDayOfNextMonth . setHours ( 0 , 0 , 0 , 0 ) ;
37
39
38
- const currentRunCount = await this . #prismaClient . jobRun . count ( {
40
+ const currentRunCount = await this . #replica . jobRun . count ( {
39
41
where : {
40
42
organizationId : orgId ,
41
43
createdAt : {
0 commit comments