chore: align tickers
Some checks failed
Some checks failed
This commit is contained in:
parent
d92447ad1b
commit
cacdfab155
3 changed files with 5 additions and 12 deletions
|
|
@ -111,8 +111,7 @@ func (conn *Connector) GetScheduleLimit(duration int) (float64, error) {
|
||||||
// WatchDog triggers meter values messages if older than timeout.
|
// WatchDog triggers meter values messages if older than timeout.
|
||||||
// Must be wrapped in a goroutine.
|
// Must be wrapped in a goroutine.
|
||||||
func (conn *Connector) WatchDog(ctx context.Context, timeout time.Duration) {
|
func (conn *Connector) WatchDog(ctx context.Context, timeout time.Duration) {
|
||||||
tick := time.NewTicker(2 * time.Second)
|
for tick := time.NewTicker(2 * time.Second); ; {
|
||||||
for {
|
|
||||||
conn.mu.Lock()
|
conn.mu.Lock()
|
||||||
update := conn.clock.Since(conn.meterUpdated) > timeout
|
update := conn.clock.Since(conn.meterUpdated) > timeout
|
||||||
conn.mu.Unlock()
|
conn.mu.Unlock()
|
||||||
|
|
|
||||||
|
|
@ -328,14 +328,11 @@ func (c *Pulsatrix) parseMessage(messageType websocket.MessageType, message []by
|
||||||
func (c *Pulsatrix) heartbeat(ctx context.Context) {
|
func (c *Pulsatrix) heartbeat(ctx context.Context) {
|
||||||
defer c.wg.Done()
|
defer c.wg.Done()
|
||||||
|
|
||||||
ticker := time.NewTicker(heartbeatInterval)
|
for tick := time.NewTicker(heartbeatInterval); ; {
|
||||||
defer ticker.Stop()
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case <-ticker.C:
|
case <-tick.C:
|
||||||
enabled := atomic.LoadInt32(&c.enabled) != 0
|
enabled := atomic.LoadInt32(&c.enabled) != 0
|
||||||
if err := c.Enable(enabled); err != nil {
|
if err := c.Enable(enabled); err != nil {
|
||||||
atomic.AddInt32(&c.consecutiveHeartbeatErrors, 1)
|
atomic.AddInt32(&c.consecutiveHeartbeatErrors, 1)
|
||||||
|
|
|
||||||
|
|
@ -156,12 +156,9 @@ func NewSEMP(ctx context.Context, uri, deviceID string, cache time.Duration) (ap
|
||||||
|
|
||||||
// heartbeat ensures that device control updates are sent at least once per minute
|
// heartbeat ensures that device control updates are sent at least once per minute
|
||||||
func (wb *SEMP) heartbeat(ctx context.Context) {
|
func (wb *SEMP) heartbeat(ctx context.Context) {
|
||||||
ticker := time.NewTicker(time.Second)
|
for tick := time.NewTicker(time.Second); ; {
|
||||||
defer ticker.Stop()
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-tick.C:
|
||||||
// Check if we need to send an update
|
// Check if we need to send an update
|
||||||
if time.Since(wb.conn.Updated()) >= time.Minute {
|
if time.Since(wb.conn.Updated()) >= time.Minute {
|
||||||
if err := wb.conn.SendDeviceControl(wb.deviceID, wb.calcPower(wb.enabled, wb.current, wb.phases)); err != nil {
|
if err := wb.conn.SendDeviceControl(wb.deviceID, wb.calcPower(wb.enabled, wb.current, wb.phases)); err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue