File tree 2 files changed +28
-22
lines changed
2 files changed +28
-22
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ const logger = new Logger();
23
23
await initApp ( ) ;
24
24
await connectDB ( ) ;
25
25
await associateModels ( ) ;
26
+ await jobs ( ) ;
26
27
27
28
// Create server for Express API and WebSockets
28
29
const server = http . createServer ( ) ;
Original file line number Diff line number Diff line change @@ -6,30 +6,35 @@ const Logger = require('./Logger');
6
6
const loadConfig = require ( './loadConfig' ) ;
7
7
const logger = new Logger ( ) ;
8
8
9
- // Update weather data every 15 minutes
10
- const weatherJob = schedule . scheduleJob (
11
- 'updateWeather' ,
12
- '0 */15 * * * *' ,
13
- async ( ) => {
14
- const { WEATHER_API_KEY : secret } = await loadConfig ( ) ;
9
+ module . exports = async function ( ) {
10
+ const { WEATHER_API_KEY } = await loadConfig ( ) ;
11
+ const FEAT_WHEATHER_ENABLED = WEATHER_API_KEY != '' ;
15
12
16
- try {
17
- const weatherData = await getExternalWeather ( ) ;
13
+ if ( FEAT_WHEATHER_ENABLED ) {
14
+ // Update weather data every 15 minutes
15
+ const weatherJob = schedule . scheduleJob (
16
+ 'updateWeather' ,
17
+ '0 */15 * * * *' ,
18
+ async ( ) => {
19
+ try {
20
+ const weatherData = await getExternalWeather ( ) ;
18
21
19
- Sockets . getSocket ( 'weather' ) . socket . send ( JSON . stringify ( weatherData ) ) ;
20
- } catch ( err ) {
21
- if ( secret ) {
22
- logger . log ( err . message , 'ERROR' ) ;
22
+ Sockets . getSocket ( 'weather' ) . socket . send ( JSON . stringify ( weatherData ) ) ;
23
+ } catch ( err ) {
24
+ if ( WEATHER_API_KEY ) {
25
+ logger . log ( err . message , 'ERROR' ) ;
26
+ }
27
+ }
23
28
}
24
- }
25
- }
26
- ) ;
29
+ ) ;
27
30
28
- // Clear old weather data every 4 hours
29
- const weatherCleanerJob = schedule . scheduleJob (
30
- 'clearWeather' ,
31
- '0 5 */4 * * *' ,
32
- async ( ) => {
33
- clearWeatherData ( ) ;
31
+ // Clear old weather data every 4 hours
32
+ const weatherCleanerJob = schedule . scheduleJob (
33
+ 'clearWeather' ,
34
+ '0 5 */4 * * *' ,
35
+ async ( ) => {
36
+ clearWeatherData ( ) ;
37
+ }
38
+ ) ;
34
39
}
35
- ) ;
40
+ } ;
You can’t perform that action at this time.
0 commit comments