Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkg/heartbeat/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type HeartbeatService struct {
interval time.Duration
enabled bool
mu sync.RWMutex
started bool
stopChan chan struct{}
}

Expand All @@ -31,14 +32,15 @@ func (hs *HeartbeatService) Start() error {
hs.mu.Lock()
defer hs.mu.Unlock()

if hs.running() {
if hs.started {
return nil
}

if !hs.enabled {
return fmt.Errorf("heartbeat service is disabled")
}

hs.started = true
go hs.runLoop()

return nil
Expand All @@ -48,10 +50,11 @@ func (hs *HeartbeatService) Stop() {
hs.mu.Lock()
defer hs.mu.Unlock()

if !hs.running() {
if !hs.started {
return
}

hs.started = false
close(hs.stopChan)
}

Expand Down