mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-19 03:29:37 +02:00
Docker build. Catch client routes on server. Initial config utility
This commit is contained in:
parent
d2e6ebae4f
commit
1636b705de
10 changed files with 125 additions and 13 deletions
36
utils/initConfig.js
Normal file
36
utils/initConfig.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
const { Op } = require('sequelize');
|
||||
const Config = require('../models/Config');
|
||||
|
||||
const initConfig = async () => {
|
||||
// Config keys
|
||||
const keys = ['WEATHER_API_KEY', 'lat', 'long', 'isCelsius'];
|
||||
const values = ['', 0, 0, true];
|
||||
|
||||
// Get config values
|
||||
const configPairs = await Config.findAll({
|
||||
where: {
|
||||
key: {
|
||||
[Op.or]: keys
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Get key from each pair
|
||||
const configKeys = configPairs.map((pair) => pair.key);
|
||||
|
||||
// Create missing pairs
|
||||
keys.forEach(async (key, idx) => {
|
||||
if (!configKeys.includes(key)) {
|
||||
await Config.create({
|
||||
key,
|
||||
value: values[idx],
|
||||
valueType: typeof values[idx]
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
console.log('Initial config created');
|
||||
return;
|
||||
}
|
||||
|
||||
module.exports = initConfig;
|
|
@ -2,6 +2,7 @@ const schedule = require('node-schedule');
|
|||
const getExternalWeather = require('./getExternalWeather');
|
||||
const Sockets = require('../Sockets');
|
||||
|
||||
// Update weather data every 15 minutes
|
||||
const weatherJob = schedule.scheduleJob('updateWeather', '0 */15 * * * *', async () => {
|
||||
try {
|
||||
const weatherData = await getExternalWeather();
|
||||
|
@ -10,4 +11,9 @@ const weatherJob = schedule.scheduleJob('updateWeather', '0 */15 * * * *', async
|
|||
} catch (err) {
|
||||
console.log(err.message);
|
||||
}
|
||||
})
|
||||
|
||||
// Clear old weather data every 4 hours
|
||||
const weatherCleanerJob = schedule.scheduleJob('clearWeather', '0 0 */4 * * *', async () => {
|
||||
console.log('clean')
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue