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

@@ -718,6 +718,19 @@ Analyze all provided screenshots comprehensively and return only the JSON respon
setTimeout(() => progressTracker.deleteSession(sessionId), 1000)
}
// Trigger post-analysis cleanup in development mode
if (process.env.NODE_ENV === 'development') {
try {
// Dynamic import to avoid circular dependencies
const aggressiveCleanupModule = await import('./aggressive-cleanup')
const aggressiveCleanup = aggressiveCleanupModule.default
// Run cleanup in background, don't block the response
aggressiveCleanup.runPostAnalysisCleanup().catch(console.error)
} catch (cleanupError) {
console.error('Error triggering post-analysis cleanup:', cleanupError)
}
}
return {
screenshots,
analysis