fix: Improve automation stop functionality and add debug logging

Stop API improvements:
- Added comprehensive debug logging for stop process
- Changed session status from INACTIVE to STOPPED for clarity
- Better error tracking and result reporting

Automation service improvements:
- Added isRunning check at start of runAutomationCycle to prevent zombie cycles
- Enhanced stop method with better logging and state reset
- Proper config cleanup after database update to prevent residual processes
- More robust interval clearing and state management

These changes should fix the issue where automation appears stopped
but continues running in background.
This commit is contained in:
mindesbunister
2025-07-24 17:42:50 +02:00
parent 1a32cdec8c
commit 8c80c577cb
2 changed files with 19 additions and 4 deletions

View File

@@ -214,7 +214,11 @@ export class AutomationService {
}
private async runAutomationCycle(): Promise<void> {
if (!this.config) return
// Check if automation should still be running
if (!this.isRunning || !this.config) {
console.log('🛑 Automation cycle stopped - isRunning:', this.isRunning, 'config:', !!this.config)
return
}
try {
console.log(`🔍 Running automation cycle for ${this.config.symbol} ${this.config.timeframe}`)
@@ -1310,14 +1314,19 @@ ${validResults.map(r => `• ${r.timeframe}: ${r.analysis?.recommendation} (${r.
async stopAutomation(): Promise<boolean> {
try {
console.log('🛑 Stopping automation service...')
this.isRunning = false
// Clear the interval if it exists
if (this.intervalId) {
console.log('🛑 Clearing automation interval')
clearInterval(this.intervalId)
this.intervalId = null
}
// Reset config to prevent any residual processes
this.config = null
// Stop price monitoring
try {
await priceMonitorService.stopMonitoring()