From f29aae91c22d1baa44801e5ab10d50fd3855d47d Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sat, 4 Jan 2025 00:53:14 -0600 Subject: [PATCH] refactor: add env --- apps/golang/main.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/golang/main.go b/apps/golang/main.go index ac7ee115b..ae5280778 100644 --- a/apps/golang/main.go +++ b/apps/golang/main.go @@ -172,7 +172,18 @@ func main() { // Start metrics collection in background go func() { - ticker := time.NewTicker(10 * time.Second) + refreshRate := os.Getenv("REFRESH_RATE_SERVER") + + log.Printf("REFRESH_RATE_SERVER: %v", refreshRate) + duration := 10 * time.Second // default value + if refreshRate != "" { + if seconds, err := strconv.Atoi(refreshRate); err == nil { + duration = time.Duration(seconds) * time.Second + } else { + log.Printf("Invalid REFRESH_RATE_SERVER value, using default: %v", err) + } + } + ticker := time.NewTicker(duration) for range ticker.C { metrics := getServerMetrics() if err := db.SaveMetric(metrics); err != nil {