diff --git a/server/db/db_test.go b/server/db/db_test.go index 5b8f8d1..af93407 100644 --- a/server/db/db_test.go +++ b/server/db/db_test.go @@ -28,6 +28,9 @@ func TestMain(m *testing.M) { log.Fatalf("Database connection is not initialized") } + // Set relevant environment variables + os.Setenv("UPDATE_INTERVAL_IN_HOURS", "24") + // Run tests code := m.Run() diff --git a/server/db/update_counter.go b/server/db/update_counter.go index 7d32061..daf1036 100644 --- a/server/db/update_counter.go +++ b/server/db/update_counter.go @@ -105,7 +105,15 @@ func upsertCounterData(tableName string) (bool, error) { } } - if time.Since(lastUpdated) < 24*time.Hour { + updateIntervalInt, err := utils.GetEnvInt("UPDATE_INTERVAL_IN_HOURS") + if err != nil { + return false, fmt.Errorf("❌ Error getting UPDATE_INTERVAL_IN_HOURS environment variable.\n %s", err) + } + + updateInterval := time.Duration(updateIntervalInt) + log.Printf("🕒 UPDATE_INTERVAL_IN_HOURS: %d", updateInterval) + + if time.Since(lastUpdated) < updateInterval*time.Hour { log.Println("🙅 24 hours have not passed since the last update. Counter not increased...") return false, nil }