fix_: fix ticker in metrics

Create ticker in Start() instead of one global in service

Fix #5548
This commit is contained in:
Michal Iskierko 2024-07-22 10:56:17 +02:00 committed by Michał Iskierko
parent 0456dcef8b
commit 8bb0bb0b3c
1 changed files with 3 additions and 1 deletions

View File

@ -33,6 +33,7 @@ type MetricService struct {
done chan bool done chan bool
started bool started bool
wg sync.WaitGroup wg sync.WaitGroup
interval time.Duration
} }
func NewDefaultMetricService(db *sql.DB) *MetricService { func NewDefaultMetricService(db *sql.DB) *MetricService {
@ -45,7 +46,7 @@ func NewMetricService(repository MetricRepository, processor common.MetricProces
return &MetricService{ return &MetricService{
repository: repository, repository: repository,
processor: processor, processor: processor,
ticker: time.NewTicker(interval), interval: interval,
done: make(chan bool), done: make(chan bool),
} }
} }
@ -54,6 +55,7 @@ func (s *MetricService) Start() {
if s.started { if s.started {
return return
} }
s.ticker = time.NewTicker(s.interval)
s.wg.Add(1) s.wg.Add(1)
s.started = true s.started = true
go func() { go func() {