@@ -176,37 +176,30 @@ func addWeatherLocation(ctx context.Context, location config.WeatherLocation, wi
176
176
}
177
177
}
178
178
179
+ var forecastCh <- chan time.Time
180
+ if withForecast && forecastTicker != nil {
181
+ forecastCh = forecastTicker .C
182
+ }
179
183
for {
180
184
select {
181
185
case <- ctx .Done ():
182
186
log .Debug ("Stopping weather updates for" , "name" , w .Name )
183
187
return
184
188
case <- weatherTicker .C :
185
189
log .Debug ("Getting weather for" , "name" , w .Name )
186
- newWeather , newWeatherErr := w .updateWeather (ctx )
187
- if newWeatherErr != nil {
188
- log .Error ("Failed to update weather" , "name" , w .Name , "error" , newWeatherErr )
189
- continue
190
+ if newWeather , err := w .updateWeather (ctx ); err != nil {
191
+ log .Error ("Failed to update weather" , "name" , w .Name , "error" , err )
192
+ } else {
193
+ weatherDataStore .Store (strings .ToLower (w .Name ), newWeather )
194
+ log .Debug ("Retrieved weather for" , "name" , w .Name )
190
195
}
191
- weatherDataStore .Store (strings .ToLower (w .Name ), newWeather )
192
- log .Debug ("Retrieved weather for" , "name" , w .Name )
193
- default :
194
- if withForecast && forecastTicker != nil {
195
- select {
196
- case <- forecastTicker .C :
197
- log .Debug ("Getting forecast for" , "name" , w .Name )
198
- newForecast , newForecastErr := w .updateForecast (ctx )
199
- if newForecastErr != nil {
200
- log .Error ("Failed to update forecast" , "name" , w .Name , "error" , newForecastErr )
201
- continue
202
- }
203
- weatherDataStore .Store (strings .ToLower (w .Name ), newForecast )
204
- log .Debug ("Retrieved forecast for" , "name" , w .Name )
205
- default :
206
- time .Sleep (100 * time .Millisecond )
207
- }
196
+ case <- forecastCh :
197
+ log .Debug ("Getting forecast for" , "name" , w .Name )
198
+ if newForecast , err := w .updateForecast (ctx ); err != nil {
199
+ log .Error ("Failed to update forecast" , "name" , w .Name , "error" , err )
208
200
} else {
209
- time .Sleep (100 * time .Millisecond )
201
+ weatherDataStore .Store (strings .ToLower (w .Name ), newForecast )
202
+ log .Debug ("Retrieved forecast for" , "name" , w .Name )
210
203
}
211
204
}
212
205
}
0 commit comments