add rate limit for refresh
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This commit is contained in:
		
							
								
								
									
										9
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								main.go
									
									
									
									
									
								
							@@ -11,6 +11,7 @@ import (
 | 
				
			|||||||
var (
 | 
					var (
 | 
				
			||||||
	configuredProviders []AccountProvider // Any account providers that are successfully configured get added to this slice
 | 
						configuredProviders []AccountProvider // Any account providers that are successfully configured get added to this slice
 | 
				
			||||||
	ynabClient          *ynab.Client      // YNAB HTTP client
 | 
						ynabClient          *ynab.Client      // YNAB HTTP client
 | 
				
			||||||
 | 
						lastRefresh         time.Time
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Called at program startup or if SIGHUP is received
 | 
					// Called at program startup or if SIGHUP is received
 | 
				
			||||||
@@ -61,6 +62,14 @@ func main() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func refreshData() {
 | 
					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
 | 
						// Loop through each configured account provider and attempt to get the account balances, and update YNAB
 | 
				
			||||||
	for _, p := range configuredProviders {
 | 
						for _, p := range configuredProviders {
 | 
				
			||||||
		balances, accountIDs, err := p.GetBalances()
 | 
							balances, accountIDs, err := p.GetBalances()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user