add rate limit for refresh
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Steven Polley 2023-11-13 14:55:48 -07:00
parent a95df7c42b
commit feaa07e251
1 changed files with 9 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import (
var (
configuredProviders []AccountProvider // Any account providers that are successfully configured get added to this slice
ynabClient *ynab.Client // YNAB HTTP client
lastRefresh time.Time
)
// Called at program startup or if SIGHUP is received
@ -61,6 +62,14 @@ func main() {
}
func refreshData() {
// Only allow a refresh at most once every 5 minutes
if time.Now().Before(lastRefresh.Add(time.Minute * 5)) {
log.Printf("refresh rate limited")
return
}
lastRefresh = time.Now()
// Loop through each configured account provider and attempt to get the account balances, and update YNAB
for _, p := range configuredProviders {
balances, accountIDs, err := p.GetBalances()