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:
@@ -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) {
|
||||
|
||||
@@ -113,6 +113,17 @@ export async function POST(request) {
|
||||
message: `Successfully captured ${screenshots.length} screenshot(s)${analysis ? ' with AI analysis' : ''}`
|
||||
}
|
||||
|
||||
// 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-analysis cleanup:', cleanupError)
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json(result)
|
||||
} catch (error) {
|
||||
console.error('Enhanced screenshot API error:', error)
|
||||
|
||||
Reference in New Issue
Block a user