Add read-only mode support and enhance logging throughout the application
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2026-02-19 12:36:52 +11:00
parent bdcb8e6f73
commit 1c15ff5911
8 changed files with 281 additions and 33 deletions

View File

@@ -2,8 +2,11 @@ package mk2core
import (
"git.coadcorp.com/nathan/invertergui/mk2driver"
"github.com/sirupsen/logrus"
)
var log = logrus.WithField("ctx", "inverter-gui-core")
type Core struct {
mk2driver.Mk2
plugins map[*subscription]bool
@@ -16,6 +19,7 @@ func NewCore(m mk2driver.Mk2) *Core {
register: make(chan *subscription, 255),
plugins: map[*subscription]bool{},
}
log.Info("Core initialized")
go core.run()
return core
}
@@ -25,6 +29,7 @@ func (c *Core) NewSubscription() mk2driver.Mk2 {
send: make(chan *mk2driver.Mk2Info),
}
c.register <- sub
log.Debug("New plugin subscription registered")
return sub
}
@@ -33,11 +38,13 @@ func (c *Core) run() {
select {
case r := <-c.register:
c.plugins[r] = true
log.WithField("subscribers", len(c.plugins)).Debug("Subscription added")
case e := <-c.C():
for plugin := range c.plugins {
select {
case plugin.send <- e:
default:
log.WithField("subscribers", len(c.plugins)).Warn("Dropping update for a slow subscriber")
}
}
}