Skip to content

Commit

Permalink
feat: set update time interval by UPDATE_INTERVAL_IN_HOURS env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
mgierada committed Jun 6, 2024
1 parent 5ad47b0 commit 66ee06e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions server/db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
10 changes: 9 additions & 1 deletion server/db/update_counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 66ee06e

Please sign in to comment.