Fix UI synchronization: automation status now properly reflects running state
- Add isRunning check in runCycle to prevent zombie automation cycles - Enhance status reporting with detailed status and next action descriptions - Add clear logging for start/stop operations with isRunning status - Fix disconnect between background intervals and UI status display - Stop button should now work properly when automation is actually running UI will now correctly show when automation is running vs stopped
This commit is contained in:
@@ -42,6 +42,9 @@ class SimpleAutomation {
|
||||
this.isRunning = true;
|
||||
this.stats.startTime = new Date().toISOString();
|
||||
this.stats.status = 'Running';
|
||||
|
||||
console.log('✅ AUTOMATION STATUS: isRunning =', this.isRunning);
|
||||
console.log('🎯 LIVE TRADING:', this.config.enableTrading ? 'ENABLED' : 'DISABLED');
|
||||
this.stats.totalCycles = 0;
|
||||
|
||||
// Auto-enable trading when in LIVE mode
|
||||
@@ -94,8 +97,10 @@ class SimpleAutomation {
|
||||
|
||||
async stop() {
|
||||
try {
|
||||
console.log('🛑 STOPPING AUTOMATION...');
|
||||
this.isRunning = false;
|
||||
this.stats.status = 'Stopped';
|
||||
console.log('✅ AUTOMATION STATUS: isRunning =', this.isRunning);
|
||||
|
||||
if (this.intervalId) {
|
||||
clearInterval(this.intervalId);
|
||||
@@ -113,6 +118,12 @@ class SimpleAutomation {
|
||||
|
||||
async runCycle() {
|
||||
try {
|
||||
// Check if automation should still be running
|
||||
if (!this.isRunning) {
|
||||
console.log('⏹️ AUTOMATION STOPPED: Skipping cycle');
|
||||
return;
|
||||
}
|
||||
|
||||
this.stats.totalCycles++;
|
||||
this.stats.lastActivity = new Date().toISOString();
|
||||
|
||||
@@ -469,7 +480,7 @@ class SimpleAutomation {
|
||||
}
|
||||
|
||||
getStatus() {
|
||||
return {
|
||||
const baseStatus = {
|
||||
isActive: this.isRunning,
|
||||
mode: this.config?.mode || 'SIMULATION',
|
||||
enableTrading: this.config?.enableTrading || false,
|
||||
@@ -479,6 +490,17 @@ class SimpleAutomation {
|
||||
automationType: 'SIMPLE',
|
||||
...this.stats
|
||||
};
|
||||
|
||||
// Add more descriptive status based on running state
|
||||
if (this.isRunning) {
|
||||
baseStatus.detailedStatus = 'Running - Monitoring for trade opportunities';
|
||||
baseStatus.nextAction = 'Next analysis cycle in progress';
|
||||
} else {
|
||||
baseStatus.detailedStatus = 'Stopped - No monitoring active';
|
||||
baseStatus.nextAction = 'Start automation to begin monitoring';
|
||||
}
|
||||
|
||||
return baseStatus;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user