feat: implement on-demand cleanup triggered after analysis completion

- Replace time-based cleanup with on-demand cleanup in development mode
- Cleanup is triggered immediately after AI analysis completes
- Added runPostAnalysisCleanup() method to aggressive-cleanup service
- Cleanup triggers added to both single and batch analysis endpoints
- More efficient: cleanup happens only when needed, not on timer
- Prevents zombie processes without interfering with active analysis
- Production mode still uses periodic cleanup as backup (10 min intervals)
- Gentle cleanup in development: SIGTERM first, then SIGKILL if needed
This commit is contained in:
mindesbunister
2025-07-18 19:11:15 +02:00
parent 2bdf9e2b41
commit 74b0087f17
4 changed files with 84 additions and 12 deletions

View File

@@ -206,6 +206,17 @@ export async function POST(request) {
// Clean up session
setTimeout(() => progressTracker.deleteSession(sessionId), 2000)
// Trigger post-analysis cleanup in development mode
if (process.env.NODE_ENV === 'development') {
try {
const { default: aggressiveCleanup } = await import('../../../lib/aggressive-cleanup')
// Run cleanup in background, don't block the response
aggressiveCleanup.runPostAnalysisCleanup().catch(console.error)
} catch (cleanupError) {
console.error('Error triggering post-batch-analysis cleanup:', cleanupError)
}
}
return NextResponse.json(result)
} catch (error) {