Files
Pulse/internal/monitoring/notification_producers.go
pulse-triage[bot] 2cb5e3fd68 Drain alert notification producers before stopping delivery
Own callback admission before scheduling, wait for accepted alert callbacks while their stores remain open, and drain monitor handoffs before notification Stop. Preserve synchronous callback behavior, existing destination policy and occurrence snapshots.

Contract-Neutral: Repairs existing graceful notification shutdown without changing public APIs, payloads, policy, authority or retention.
Change-source: pulse-maintainer
2026-11-06 18:09:00 +00:00

36 lines
751 B
Go

package monitoring
import "sync"
// notificationProducers owns the handoff from monitor callbacks to the
// notification manager. Taking the lease before launching the goroutine keeps a
// scheduled SendAlert/SendResolvedAlert from arriving after notification Stop.
// The zero value is ready for use, including monitors stopped before Start.
type notificationProducers struct {
mu sync.Mutex
closed bool
wg sync.WaitGroup
}
func (p *notificationProducers) start(send func()) bool {
p.mu.Lock()
if p.closed {
p.mu.Unlock()
return false
}
p.wg.Add(1)
p.mu.Unlock()
go func() {
defer p.wg.Done()
send()
}()
return true
}
func (p *notificationProducers) stop() {
p.mu.Lock()
p.closed = true
p.mu.Unlock()
p.wg.Wait()
}