Skip to content

Commit

Permalink
refactor: add env
Browse files Browse the repository at this point in the history
  • Loading branch information
Siumauricio committed Jan 4, 2025
1 parent 4dadf7d commit f29aae9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion apps/golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f29aae9

Please sign in to comment.