Perform proxy updates in goroutines
This commit is contained in:
parent
eaf2cf211d
commit
f87b35b306
@ -7,6 +7,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
|
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
@ -120,7 +121,13 @@ func (aw *AmbientWeather) handleProviderRequest(
|
|||||||
// Uses a weather update to allow awn to publish to wunderground and
|
// Uses a weather update to allow awn to publish to wunderground and
|
||||||
// visa versa.
|
// visa versa.
|
||||||
if station := update.StationConfig; station != nil {
|
if station := update.StationConfig; station != nil {
|
||||||
|
// Perform proxy updates in parallel if enabled
|
||||||
|
var proxyWg sync.WaitGroup
|
||||||
|
|
||||||
if station.ProxyToAWN {
|
if station.ProxyToAWN {
|
||||||
|
proxyWg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer proxyWg.Done()
|
||||||
err := aw.awnProvider.ProxyReq(ctx, update)
|
err := aw.awnProvider.ProxyReq(ctx, update)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zerolog.Ctx(aw.appCtx).Err(err).Msg("failed to proxy to ambient weather")
|
zerolog.Ctx(aw.appCtx).Err(err).Msg("failed to proxy to ambient weather")
|
||||||
@ -129,8 +136,13 @@ func (aw *AmbientWeather) handleProviderRequest(
|
|||||||
zerolog.Ctx(aw.appCtx).Debug().
|
zerolog.Ctx(aw.appCtx).Debug().
|
||||||
Str("station", station.Name).
|
Str("station", station.Name).
|
||||||
Msg("proxied weather update to awn")
|
Msg("proxied weather update to awn")
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
if station.ProxyToWunderground {
|
if station.ProxyToWunderground {
|
||||||
|
proxyWg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer proxyWg.Done()
|
||||||
err := aw.wuProvider.ProxyReq(ctx, update)
|
err := aw.wuProvider.ProxyReq(ctx, update)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zerolog.Ctx(aw.appCtx).Err(err).Msg("failed to proxy to ambient weather")
|
zerolog.Ctx(aw.appCtx).Err(err).Msg("failed to proxy to ambient weather")
|
||||||
@ -139,7 +151,10 @@ func (aw *AmbientWeather) handleProviderRequest(
|
|||||||
zerolog.Ctx(aw.appCtx).Debug().
|
zerolog.Ctx(aw.appCtx).Debug().
|
||||||
Str("station", station.Name).
|
Str("station", station.Name).
|
||||||
Msg("proxied weather update to wunderground")
|
Msg("proxied weather update to wunderground")
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proxyWg.Wait()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user