update every hour at 59 minutes
This commit is contained in:
		
							
								
								
									
										29
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								main.go
									
									
									
									
									
								
							@@ -69,8 +69,33 @@ func main() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	for { // Main program loop
 | 
						for { // Main program loop
 | 
				
			||||||
		refreshData()
 | 
							refreshData()
 | 
				
			||||||
		log.Print("Sleeping for 6 hours...")
 | 
					
 | 
				
			||||||
		time.Sleep(time.Hour * 6)
 | 
							// Update at 59 minutes on the hour
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Get current time
 | 
				
			||||||
 | 
							now := time.Now()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Calculate the next time at 59 minutes
 | 
				
			||||||
 | 
							next := time.Date(
 | 
				
			||||||
 | 
								now.Year(),
 | 
				
			||||||
 | 
								now.Month(),
 | 
				
			||||||
 | 
								now.Day(),
 | 
				
			||||||
 | 
								now.Hour(),
 | 
				
			||||||
 | 
								59,
 | 
				
			||||||
 | 
								0,
 | 
				
			||||||
 | 
								0,
 | 
				
			||||||
 | 
								now.Location(),
 | 
				
			||||||
 | 
							)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// If we've already passed this hour's 59th minute, go to next hour
 | 
				
			||||||
 | 
							if !next.After(now) {
 | 
				
			||||||
 | 
								next = next.Add(time.Hour)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							// Duration to sleep
 | 
				
			||||||
 | 
							duration := time.Until(next)
 | 
				
			||||||
 | 
							log.Printf("Sleeping until %v (%v)", next, duration)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							time.Sleep(duration)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user