update concurrently
This commit is contained in:
parent
4a1a8fe8a0
commit
a02e8c5061
@ -163,24 +163,43 @@ func (aw *AmbientWeather) handleProviderRequest(
|
|||||||
updateSpan.SetAttributes(attribute.String("stationName", update.StationConfig.Name))
|
updateSpan.SetAttributes(attribute.String("stationName", update.StationConfig.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Concurrently record the now enriched update
|
||||||
|
// to the configured recorder and to otel, and proxy
|
||||||
|
// to enabled downstream providers
|
||||||
|
var updateWg sync.WaitGroup
|
||||||
|
|
||||||
// Record state
|
// Record state
|
||||||
|
updateWg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer updateWg.Done()
|
||||||
aw.weatherRecorder.Set(ctx, update)
|
aw.weatherRecorder.Set(ctx, update)
|
||||||
|
}()
|
||||||
|
|
||||||
// Update metrics
|
// Update metrics
|
||||||
|
updateWg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer updateWg.Done()
|
||||||
aw.metricsUpdate(ctx, p, update)
|
aw.metricsUpdate(ctx, p, update)
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Proxy update to one or both services if configured to do so
|
||||||
|
// Uses a weather update to allow awn to publish to wunderground and
|
||||||
|
// visa versa.
|
||||||
|
if update.StationConfig != nil {
|
||||||
|
updateWg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer updateWg.Done()
|
||||||
|
aw.proxyUpdate(ctx, p, update)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
updateWg.Wait()
|
||||||
|
|
||||||
l.Debug().
|
l.Debug().
|
||||||
Str("provider", p.Name()).
|
Str("provider", p.Name()).
|
||||||
Any("update", update).
|
Any("update", update).
|
||||||
Msg("successfully handled update")
|
Msg("successfully handled update")
|
||||||
w.Write([]byte("ok"))
|
w.Write([]byte("ok"))
|
||||||
|
|
||||||
// Proxy update to one or both services if configured to do so
|
|
||||||
// Uses a weather update to allow awn to publish to wunderground and
|
|
||||||
// visa versa.
|
|
||||||
if update.StationConfig != nil {
|
|
||||||
aw.proxyUpdate(ctx, p, update)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (aw *AmbientWeather) enrichUpdate(
|
func (aw *AmbientWeather) enrichUpdate(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user