dixitramjendra commited on
Commit
e1697fd
·
1 Parent(s): ed3dcb5

Add keep-alive mechanism to prevent HF free tier from sleeping

Browse files
Files changed (1) hide show
  1. forex_macd_dashboard.html +24 -0
forex_macd_dashboard.html CHANGED
@@ -1818,6 +1818,30 @@
1818
  document.addEventListener('DOMContentLoaded', () => updateThemeButton(isLight));
1819
  })();
1820
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1821
  // ========== PWA SERVICE WORKER ==========
1822
  let deferredInstallPrompt = null;
1823
 
 
1818
  document.addEventListener('DOMContentLoaded', () => updateThemeButton(isLight));
1819
  })();
1820
 
1821
+ // ========== KEEP-ALIVE MECHANISM ==========
1822
+ // Prevents Hugging Face free tier from sleeping during market hours
1823
+ (function initKeepAlive() {
1824
+ const PING_INTERVAL = 5 * 60 * 1000; // 5 minutes
1825
+
1826
+ function pingServer() {
1827
+ // Check if we're in market hours (roughly 4 AM - 11 PM IST / UTC+5:30)
1828
+ const now = new Date();
1829
+ const hour = now.getUTCHours();
1830
+ const istHour = (hour + 5.5) % 24; // Convert to IST
1831
+
1832
+ // Active during market hours (roughly 4 AM - 11:30 PM IST)
1833
+ if (istHour >= 4 && istHour <= 23.5) {
1834
+ fetch('/forex_macd_signals.json?keepalive=' + Date.now())
1835
+ .then(() => console.log('🔄 Keep-alive ping sent'))
1836
+ .catch(() => { }); // Silently ignore errors
1837
+ }
1838
+ }
1839
+
1840
+ // Start keep-alive pings
1841
+ setInterval(pingServer, PING_INTERVAL);
1842
+ console.log('💓 Keep-alive mechanism initialized (5 min intervals)');
1843
+ })();
1844
+
1845
  // ========== PWA SERVICE WORKER ==========
1846
  let deferredInstallPrompt = null;
1847