From d338b3a8c882118a76a86d7238ddd7cd51ec3d63 Mon Sep 17 00:00:00 2001 From: Filip Borkiewicz Date: Mon, 13 Nov 2023 12:45:28 -0600 Subject: [PATCH] Fix don't wait to collect metrics for the first time (#46) --- service/ports/timer/metrics.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/service/ports/timer/metrics.go b/service/ports/timer/metrics.go index b868fed..d27e500 100644 --- a/service/ports/timer/metrics.go +++ b/service/ports/timer/metrics.go @@ -24,11 +24,13 @@ func NewMetrics(app app.Application, logger logging.Logger) *Metrics { func (m *Metrics) Run(ctx context.Context) error { for { + if err := m.collect(ctx); err != nil { + m.logger.Error().WithError(err).Message("error triggering app handler") + } + select { case <-time.After(collectMetricsEvery): - if err := m.collect(ctx); err != nil { - m.logger.Error().WithError(err).Message("error triggering app handler") - } + continue case <-ctx.Done(): return ctx.Err() }