@@ -67,7 +67,7 @@ export async function POST(request: NextRequest) {
6767 { status : 500 }
6868 )
6969 } catch ( error ) {
70- logger . error ( 'Fatal error in monthly billing cron job' , { error } )
70+ logger . error ( 'Fatal error in daily billing cron job' , { error } )
7171
7272 return NextResponse . json (
7373 {
@@ -90,18 +90,59 @@ export async function GET(request: NextRequest) {
9090 return authError
9191 }
9292
93- return NextResponse . json ( {
94- status : 'ready' ,
95- message :
96- 'Daily billing check cron job is ready to process users and organizations with periods ending today' ,
97- currentDate : new Date ( ) . toISOString ( ) . split ( 'T' ) [ 0 ] ,
93+ const startTime = Date . now ( )
94+ const result = await processDailyBillingCheck ( )
95+ const duration = Date . now ( ) - startTime
96+
97+ if ( result . success ) {
98+ logger . info ( 'Daily billing check (GET) completed successfully' , {
99+ processedUsers : result . processedUsers ,
100+ processedOrganizations : result . processedOrganizations ,
101+ totalChargedAmount : result . totalChargedAmount ,
102+ duration : `${ duration } ms` ,
103+ } )
104+
105+ return NextResponse . json ( {
106+ success : true ,
107+ summary : {
108+ processedUsers : result . processedUsers ,
109+ processedOrganizations : result . processedOrganizations ,
110+ totalChargedAmount : result . totalChargedAmount ,
111+ duration : `${ duration } ms` ,
112+ } ,
113+ } )
114+ }
115+
116+ logger . error ( 'Daily billing check (GET) completed with errors' , {
117+ processedUsers : result . processedUsers ,
118+ processedOrganizations : result . processedOrganizations ,
119+ totalChargedAmount : result . totalChargedAmount ,
120+ errorCount : result . errors . length ,
121+ errors : result . errors ,
122+ duration : `${ duration } ms` ,
98123 } )
124+
125+ return NextResponse . json (
126+ {
127+ success : false ,
128+ summary : {
129+ processedUsers : result . processedUsers ,
130+ processedOrganizations : result . processedOrganizations ,
131+ totalChargedAmount : result . totalChargedAmount ,
132+ errorCount : result . errors . length ,
133+ duration : `${ duration } ms` ,
134+ } ,
135+ errors : result . errors ,
136+ } ,
137+ { status : 500 }
138+ )
99139 } catch ( error ) {
100- logger . error ( 'Error in billing health check ' , { error } )
140+ logger . error ( 'Fatal error in daily billing (GET) cron job ' , { error } )
101141 return NextResponse . json (
102142 {
103- status : 'error' ,
104- error : error instanceof Error ? error . message : 'Unknown error' ,
143+ success : false ,
144+ error : 'Internal server error during daily billing check' ,
145+ details : error instanceof Error ? error . message : 'Unknown error' ,
105146 } ,
106147 { status : 500 }
107148 )
0 commit comments