fix: emergency automation fix - stop runaway trading loops
- Replace automation service with emergency rate-limited version - Add 5-minute minimum interval between automation starts - Implement forced Chromium process cleanup on stop - Backup broken automation service as .broken file - Emergency service prevents multiple simultaneous automations - Fixed 1400+ Chromium process accumulation issue - Tested and confirmed: rate limiting works, processes stay at 0
This commit is contained in:
@@ -1,44 +1,25 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { automationService } from '@/lib/automation-service-simple'
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
|
||||
const prisma = new PrismaClient()
|
||||
import { emergencyAutomation } from '@/lib/emergency-automation'
|
||||
|
||||
export async function POST() {
|
||||
try {
|
||||
console.log('🛑 Stop automation request received')
|
||||
console.log('🚨 EMERGENCY: Stop request received')
|
||||
|
||||
// Stop the automation service
|
||||
console.log('🛑 Calling automationService.stopAutomation()')
|
||||
const success = await automationService.stopAutomation()
|
||||
console.log('🛑 Stop automation result:', success)
|
||||
const result = await emergencyAutomation.stop()
|
||||
|
||||
// Also update all active automation sessions in database to INACTIVE
|
||||
console.log('🛑 Updating database sessions to STOPPED')
|
||||
const updateResult = await prisma.automationSession.updateMany({
|
||||
where: {
|
||||
status: 'ACTIVE'
|
||||
},
|
||||
data: {
|
||||
status: 'STOPPED', // Use STOPPED instead of INACTIVE for clarity
|
||||
updatedAt: new Date()
|
||||
}
|
||||
})
|
||||
|
||||
console.log('🛑 Database update result:', updateResult)
|
||||
console.log('🛑 All automation sessions marked as STOPPED in database')
|
||||
|
||||
if (success) {
|
||||
return NextResponse.json({ success: true, message: 'Automation stopped successfully' })
|
||||
} else {
|
||||
return NextResponse.json({ success: false, error: 'Failed to stop automation' }, { status: 500 })
|
||||
// Also force kill any remaining processes
|
||||
try {
|
||||
const { execSync } = require('child_process')
|
||||
execSync('pkill -f "chrome|chromium" 2>/dev/null || true')
|
||||
console.log('✅ EMERGENCY: Cleanup completed')
|
||||
} catch (cleanupError) {
|
||||
console.error('Cleanup error:', cleanupError.message)
|
||||
}
|
||||
|
||||
return Response.json(result)
|
||||
} catch (error) {
|
||||
console.error('Stop automation error:', error)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Internal server error',
|
||||
message: error.message
|
||||
return Response.json({
|
||||
success: false,
|
||||
message: error.message
|
||||
}, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user