11import { startSpan } from "@internal/tracing" ;
2- import { assertExhaustive } from "@trigger.dev/core" ;
2+ import { assertExhaustive , tryCatch } from "@trigger.dev/core" ;
33import { DequeuedMessage , RetryOptions } from "@trigger.dev/core/v3" ;
44import { getMaxDuration } from "@trigger.dev/core/v3/isomorphic" ;
55import { PrismaClientOrTransaction } from "@trigger.dev/database" ;
@@ -17,6 +17,7 @@ export type DequeueSystemOptions = {
1717 machines : RunEngineOptions [ "machines" ] ;
1818 executionSnapshotSystem : ExecutionSnapshotSystem ;
1919 runAttemptSystem : RunAttemptSystem ;
20+ billing ?: RunEngineOptions [ "billing" ] ;
2021} ;
2122
2223export class DequeueSystem {
@@ -380,6 +381,24 @@ export class DequeueSystem {
380381 const currentAttemptNumber = lockedTaskRun . attemptNumber ?? 0 ;
381382 const nextAttemptNumber = currentAttemptNumber + 1 ;
382383
384+ // Get billing information if available
385+ let isPaying = false ;
386+ if ( this . options . billing ?. getCurrentPlan ) {
387+ const [ error , planResult ] = await tryCatch (
388+ this . options . billing . getCurrentPlan ( orgId )
389+ ) ;
390+
391+ if ( error ) {
392+ this . $ . logger . error ( "Failed to get billing information" , {
393+ orgId,
394+ runId,
395+ error : error . message ,
396+ } ) ;
397+ } else {
398+ isPaying = planResult . isPaying ;
399+ }
400+ }
401+
383402 const newSnapshot = await this . executionSnapshotSystem . createExecutionSnapshot (
384403 prisma ,
385404 {
@@ -448,6 +467,11 @@ export class DequeueSystem {
448467 project : {
449468 id : lockedTaskRun . projectId ,
450469 } ,
470+ billing : {
471+ currentPlan : {
472+ isPaying,
473+ } ,
474+ } ,
451475 } satisfies DequeuedMessage ;
452476 }
453477 ) ;
0 commit comments