Fix: Add error handling and timing fix for scheduler checks
This commit is contained in:
parent
6cf05184f5
commit
556199a28d
44
worker.js
44
worker.js
|
|
@ -357,18 +357,33 @@ async function checkScheduledWatering() {
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('❌ Error checking scheduled watering:', error.message);
|
console.error('❌ Error checking scheduled watering:', error.message);
|
||||||
|
console.error('Stack trace:', error.stack);
|
||||||
|
// Continue running - don't crash worker
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run check setiap 60 detik
|
// Run check setiap 60 detik
|
||||||
setInterval(checkScheduledWatering, config.worker.checkInterval);
|
setInterval(async () => {
|
||||||
|
try {
|
||||||
|
await checkScheduledWatering();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Error in scheduled check interval:', error.message);
|
||||||
|
console.error(error.stack);
|
||||||
|
}
|
||||||
|
}, config.worker.checkInterval);
|
||||||
console.log(`✅ Waktu Mode scheduler started (check every ${config.worker.checkInterval / 1000}s)`);
|
console.log(`✅ Waktu Mode scheduler started (check every ${config.worker.checkInterval / 1000}s)`);
|
||||||
|
|
||||||
// Jalankan check pertama kali setelah 5 detik (jangan tunggu 60 detik)
|
// Jalankan check pertama kali setelah 8 detik (setelah diagnostic selesai)
|
||||||
setTimeout(() => {
|
setTimeout(async () => {
|
||||||
console.log('🚀 Running first schedule check immediately...');
|
try {
|
||||||
checkScheduledWatering();
|
console.log('\n🚀 Running first schedule check immediately...');
|
||||||
}, 5000);
|
await checkScheduledWatering();
|
||||||
|
console.log('✅ First check completed successfully');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ First check failed:', error.message);
|
||||||
|
console.error(error.stack);
|
||||||
|
}
|
||||||
|
}, 8000);
|
||||||
|
|
||||||
// ==================== SENSOR MODE (THRESHOLD MONITORING) ====================
|
// ==================== SENSOR MODE (THRESHOLD MONITORING) ====================
|
||||||
|
|
||||||
|
|
@ -785,12 +800,17 @@ setTimeout(async () => {
|
||||||
|
|
||||||
// Run diagnostic checks on startup
|
// Run diagnostic checks on startup
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
console.log('\n🔧 RUNNING DIAGNOSTIC CHECKS...');
|
try {
|
||||||
await showCurrentTime();
|
console.log('\n🔧 RUNNING DIAGNOSTIC CHECKS...');
|
||||||
await checkAktuatorNode();
|
await showCurrentTime();
|
||||||
console.log('\n✅ Diagnostic checks completed');
|
await checkAktuatorNode();
|
||||||
console.log('\n💡 TIP: To test scheduler manually, check the logs above for current time');
|
console.log('\n✅ Diagnostic checks completed');
|
||||||
console.log(' Then set waktu_1 or waktu_2 in Firebase to match current time + 1 minute');
|
console.log('\n💡 TIP: To test scheduler manually, check the logs above for current time');
|
||||||
|
console.log(' Then set waktu_1 or waktu_2 in Firebase to match current time + 1 minute');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Diagnostic checks failed:', error.message);
|
||||||
|
console.error(error.stack);
|
||||||
|
}
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
// Auto-run test scheduler setiap 10 menit untuk memastikan worker alive
|
// Auto-run test scheduler setiap 10 menit untuk memastikan worker alive
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue