@@ -2,21 +2,29 @@ import { assertCronAuth } from '@/lib/api/cron-auth';
22import { processAgentJobs } from '@/lib/jobs/process' ;
33import { runErasureBatch } from '@/lib/data-rights/erasure' ;
44
5- /** One cron hit should clear backlog, not just 10 jobs every 5 minutes. */
6- const DRAIN_ROUNDS = 4 ;
5+ /**
6+ * Hobby functions die at ~300s. Keep headroom: GHA curl max-time is 280s.
7+ * More backlog drains on the next 5m cron + reclaimStaleRunningJobs.
8+ */
9+ const DRAIN_ROUNDS = 2 ;
10+ const WALL_MS = 240_000 ;
711
812async function processJobs ( limit ?: number ) {
13+ const started = Date . now ( ) ;
914 const erasures = await runErasureBatch ( ) ;
1015 const totals = { processed : 0 , succeeded : 0 , failed : 0 , reclaimed : 0 } ;
1116 for ( let i = 0 ; i < DRAIN_ROUNDS ; i += 1 ) {
12- const result = await processAgentJobs ( { limit } ) ;
17+ if ( Date . now ( ) - started > WALL_MS ) break ;
18+ const result = await processAgentJobs ( {
19+ limit : limit ?? 8 ,
20+ } ) ;
1321 totals . processed += result . processed ;
1422 totals . succeeded += result . succeeded ;
1523 totals . failed += result . failed ;
1624 totals . reclaimed += result . reclaimed ;
1725 if ( result . processed === 0 ) break ;
1826 }
19- return Response . json ( { ...totals , erasures } ) ;
27+ return Response . json ( { ...totals , erasures, elapsed_ms : Date . now ( ) - started } ) ;
2028}
2129
2230export async function GET ( request : Request ) {
0 commit comments