From 4540a91aeac1ea47a76366abe2208620893caf43 Mon Sep 17 00:00:00 2001 From: metonymic-smokey Date: Thu, 16 Sep 2021 10:38:12 +0530 Subject: [PATCH] moved API call in async --- async.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/async.go b/async.go index f37b53d..49d5d39 100644 --- a/async.go +++ b/async.go @@ -10,14 +10,17 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" ) -func recordMetrics(temp float64) { - go func() { - for { - opsProcessed.Inc() - jobsInQueue.Set(temp) - time.Sleep(2 * time.Second) +func recordMetrics() { + for { + dat := getTempData() + + for _, interval := range dat.Data.Timestep[0].TempVal { + jobsInQueue.Set(interval.Values.Temp) } - }() + + opsProcessed.Inc() + time.Sleep(2 * time.Second) + } } var opsProcessed = promauto.NewGauge( @@ -52,11 +55,7 @@ func prometheusMiddleware(next http.Handler) http.Handler { func main() { - dat := getTempData() - - for _, interval := range dat.Data.Timestep[0].TempVal { - recordMetrics(interval.Values.Temp) - } + go recordMetrics() router := mux.NewRouter() router.Use(prometheusMiddleware)