2021-05-17 19:23:54 +03:00
|
|
|
const schedule = require('node-schedule');
|
|
|
|
const getExternalWeather = require('./getExternalWeather');
|
2021-05-19 18:17:24 +03:00
|
|
|
const Sockets = require('../Sockets');
|
2021-05-17 19:23:54 +03:00
|
|
|
|
|
|
|
const weatherJob = schedule.scheduleJob('updateWeather', '0 */15 * * * *', async () => {
|
|
|
|
try {
|
2021-06-01 15:54:47 +03:00
|
|
|
const weatherData = await getExternalWeather();
|
2021-05-17 19:23:54 +03:00
|
|
|
console.log('weather updated');
|
2021-06-01 15:54:47 +03:00
|
|
|
Sockets.getSocket('weather').socket.send(JSON.stringify(weatherData));
|
2021-05-17 19:23:54 +03:00
|
|
|
} catch (err) {
|
2021-06-01 15:54:47 +03:00
|
|
|
console.log(err.message);
|
2021-05-17 19:23:54 +03:00
|
|
|
}
|
|
|
|
})
|