flame/utils/jobs.js

22 lines
785 B
JavaScript
Raw Normal View History

const schedule = require('node-schedule');
const getExternalWeather = require('./getExternalWeather');
const clearWeatherData = require('./clearWeatherData');
const Sockets = require('../Sockets');
2021-06-22 15:49:00 +03:00
const Logger = require('./Logger');
const logger = new Logger();
// Update weather data every 15 minutes
const weatherJob = schedule.scheduleJob('updateWeather', '0 */15 * * * *', async () => {
try {
const weatherData = await getExternalWeather();
2021-06-22 15:49:00 +03:00
logger.log('Weather updated');
Sockets.getSocket('weather').socket.send(JSON.stringify(weatherData));
} catch (err) {
2021-06-22 15:49:00 +03:00
logger.log(err.message, 'ERROR');
}
})
// Clear old weather data every 4 hours
const weatherCleanerJob = schedule.scheduleJob('clearWeather', '0 5 */4 * * *', async () => {
clearWeatherData();
})