Weather Station / ECOWITT / DNT
0

Configure Feed

Select the types of activity you want to include in your feed.

forcast analysis. still the same error

+34 -17
+34 -17
src/instrumentation.ts
··· 85 85 }, statsIntervalMs); 86 86 } 87 87 88 - // Schedule daily forecast storage at midnight 88 + // Schedule daily forecast storage at 20:00 (8 PM) 89 89 if (!global.__forecastPoller) { 90 90 const stationSetting = process.env.FORECAST_STATION_ID || "11035"; // or 'ALL' 91 - console.log(`[forecast] Daily forecast storage enabled for ${stationSetting === 'ALL' ? 'ALL stations' : `station ${stationSetting}`} (runs at midnight only)`); 91 + console.log(`[forecast] Daily forecast storage enabled for ${stationSetting === 'ALL' ? 'ALL stations' : `station ${stationSetting}`} (runs at 20:00 daily)`); 92 92 93 93 let lastRunDate: string | null = null; 94 94 95 - // Check every 10 minutes if it's between 00:00 and 00:30 95 + // Check every 10 minutes if it's between 20:00 and 20:30 96 96 global.__forecastPoller = setInterval(async () => { 97 97 const now = new Date(); 98 98 const currentDate = now.toISOString().split('T')[0]; 99 99 const currentHour = now.getHours(); 100 100 const currentMinute = now.getMinutes(); 101 101 102 - // Run between 00:00 and 00:30 and only once per day 102 + // Run between 20:00 and 20:30 and only once per day 103 103 if (currentHour === 20 && currentMinute <= 30 && lastRunDate !== currentDate) { 104 104 console.log(`[forecast] ========================================`); 105 - console.log(`[forecast] MIDNIGHT POLLER TRIGGERED at ${now.toISOString()}`); 105 + console.log(`[forecast] DAILY POLLER TRIGGERED at ${now.toISOString()}`); 106 106 console.log(`[forecast] ========================================`); 107 107 108 108 lastRunDate = currentDate; ··· 127 127 console.log(`[forecast] Processing ${stationIds.length} station(s)...`); 128 128 129 129 for (const sid of stationIds) { 130 - try { 131 - console.log(`[forecast] → Station ${sid}: Storing forecasts...`); 132 - await storeForecastForStation(sid); 133 - 134 - console.log(`[forecast] → Station ${sid}: Calculating analysis...`); 135 - await calculateAndStoreDailyAnalysis(sid); 136 - 137 - console.log(`[forecast] ✓ Station ${sid}: Complete`); 138 - } catch (e: any) { 139 - console.error(`[forecast] ✗ Station ${sid} failed:`, e?.message || e); 130 + const maxAttempts = 3; 131 + const retryDelayMs = 30_000; 132 + let success = false; 133 + 134 + for (let attempt = 1; attempt <= maxAttempts; attempt++) { 135 + try { 136 + console.log(`[forecast] → Station ${sid}: Storing forecasts (attempt ${attempt} of ${maxAttempts})...`); 137 + await storeForecastForStation(sid); 138 + 139 + console.log(`[forecast] → Station ${sid}: Calculating analysis (attempt ${attempt} of ${maxAttempts})...`); 140 + await calculateAndStoreDailyAnalysis(sid); 141 + 142 + console.log(`[forecast] ✓ Station ${sid}: Complete`); 143 + success = true; 144 + break; 145 + } catch (e: any) { 146 + console.error(`[forecast] ✗ Station ${sid} attempt ${attempt} failed:`, e?.message || e); 147 + if (attempt < maxAttempts) { 148 + console.log(`[forecast] → Station ${sid}: Retrying in ${retryDelayMs / 1000} seconds...`); 149 + await new Promise(r => setTimeout(r, retryDelayMs)); 150 + } 151 + } 140 152 } 153 + 154 + if (!success) { 155 + console.error(`[forecast] ✗ Station ${sid} failed after ${maxAttempts} attempts - skipping to next station`); 156 + } 157 + 141 158 // Small delay to be gentle on upstream APIs 142 159 await new Promise(r => setTimeout(r, 250)); 143 160 } 144 161 145 162 console.log(`[forecast] ========================================`); 146 - console.log(`[forecast] MIDNIGHT POLLER COMPLETE`); 163 + console.log(`[forecast] DAILY POLLER COMPLETE`); 147 164 console.log(`[forecast] ========================================`); 148 165 } catch (e: any) { 149 166 console.error("[forecast] Midnight storage failed:", e?.message || e); ··· 560 577 FROM forecasts 561 578 WHERE station_id = '${stationId}' 562 579 AND forecast_date = '${yesterdayStr}' 563 - AND storage_date < '${yesterdayStr}' 580 + AND storage_date <= '${yesterdayStr}' 564 581 ORDER BY storage_date DESC, source 565 582 `; 566 583