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:
mindesbunister
2025-07-24 20:33:20 +02:00
parent ab8fb7c202
commit 1e4f305657
23 changed files with 3837 additions and 193 deletions

View File

@@ -27,8 +27,13 @@ const LAYOUT_URLS: { [key: string]: string } = {
export class BatchScreenshotService {
private static readonly OPERATION_TIMEOUT = 180000 // 3 minutes for batch operations
private static aiSession: TradingViewAutomation | null = null
private static diySession: TradingViewAutomation | null = null
private aiSession: TradingViewAutomation | null = null
private diySession: TradingViewAutomation | null = null
private sessionId: string
constructor(sessionId?: string) {
this.sessionId = sessionId || `batch_${Date.now()}`
}
/**
* Capture screenshots for multiple timeframes and layouts in parallel
@@ -154,12 +159,12 @@ export class BatchScreenshotService {
* Get or create a persistent session for a layout
*/
private async getOrCreateSession(layout: string, credentials?: TradingViewCredentials): Promise<TradingViewAutomation> {
if (layout === 'ai' && BatchScreenshotService.aiSession) {
return BatchScreenshotService.aiSession
if (layout === 'ai' && this.aiSession) {
return this.aiSession
}
if (layout === 'diy' && BatchScreenshotService.diySession) {
return BatchScreenshotService.diySession
if (layout === 'diy' && this.diySession) {
return this.diySession
}
// Create new session
@@ -175,9 +180,9 @@ export class BatchScreenshotService {
// Store session
if (layout === 'ai') {
BatchScreenshotService.aiSession = session
this.aiSession = session
} else {
BatchScreenshotService.diySession = session
this.diySession = session
}
return session
@@ -247,14 +252,14 @@ export class BatchScreenshotService {
console.log('🧹 Cleaning up batch screenshot sessions...')
try {
if (BatchScreenshotService.aiSession) {
await BatchScreenshotService.aiSession.forceCleanup()
BatchScreenshotService.aiSession = null
if (this.aiSession) {
await this.aiSession.forceCleanup()
this.aiSession = null
}
if (BatchScreenshotService.diySession) {
await BatchScreenshotService.diySession.forceCleanup()
BatchScreenshotService.diySession = null
if (this.diySession) {
await this.diySession.forceCleanup()
this.diySession = null
}
console.log('✅ Batch screenshot cleanup completed')
@@ -280,4 +285,5 @@ export class BatchScreenshotService {
}
}
export const batchScreenshotService = new BatchScreenshotService()
// Export a factory function instead of a singleton instance
export const createBatchScreenshotService = (sessionId?: string) => new BatchScreenshotService(sessionId)