Skip to content

Commit

Permalink
moved API call in async
Browse files Browse the repository at this point in the history
  • Loading branch information
metonymic-smokey committed Sep 16, 2021
1 parent 8ab9892 commit 4540a91
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions async.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4540a91

Please sign in to comment.