Use reloaded configuration in mainloop

This commit is contained in:
Søren Rasmussen 2022-08-02 16:08:49 +02:00
parent 52b1108798
commit 5ecc4ba27a

View file

@ -35,10 +35,13 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream) {
// Controller
config := configuration.Global()
ctrl := controllers.NewChamberController(config)
chConfigChange := make(chan configuration.Configuration, 1)
chn := configuration.NewChangeNotifier()
viper.OnConfigChange(chn.OnConfigChange)
// Configuration updates
chn.Subscribe(chConfigChange)
chn.Subscribe(temperature.ConfigUpdate)
chn.Subscribe(ctrl.ConfigUpdates)
//chn.Subscribe(display.ConfiguUpdate)
@ -129,6 +132,9 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream) {
ingest.AddState(state)
//display.SetState(state)
case c := <-chConfigChange:
config = c
case <-ctx.Done():
return
}