Merge pull request #64 from DevEverything01/fix/heartbeat-service-start-bug
fix(heartbeat): resolve bug where service could never start
This commit is contained in:
@@ -14,6 +14,7 @@ type HeartbeatService struct {
|
|||||||
interval time.Duration
|
interval time.Duration
|
||||||
enabled bool
|
enabled bool
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
|
started bool
|
||||||
stopChan chan struct{}
|
stopChan chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ func (hs *HeartbeatService) Start() error {
|
|||||||
hs.mu.Lock()
|
hs.mu.Lock()
|
||||||
defer hs.mu.Unlock()
|
defer hs.mu.Unlock()
|
||||||
|
|
||||||
if hs.running() {
|
if hs.started {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,6 +40,7 @@ func (hs *HeartbeatService) Start() error {
|
|||||||
return fmt.Errorf("heartbeat service is disabled")
|
return fmt.Errorf("heartbeat service is disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hs.started = true
|
||||||
go hs.runLoop()
|
go hs.runLoop()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -48,10 +50,11 @@ func (hs *HeartbeatService) Stop() {
|
|||||||
hs.mu.Lock()
|
hs.mu.Lock()
|
||||||
defer hs.mu.Unlock()
|
defer hs.mu.Unlock()
|
||||||
|
|
||||||
if !hs.running() {
|
if !hs.started {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hs.started = false
|
||||||
close(hs.stopChan)
|
close(hs.stopChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user