Wait until next full hour

This commit is contained in:
ekzyis 2023-04-27 00:41:57 +02:00
parent 5388480f31
commit 2a9b7c6737
1 changed files with 9 additions and 2 deletions

11
main.go
View File

@ -6,13 +6,20 @@ import (
"time" "time"
) )
func WaitUntilNextHour() {
now := time.Now()
dur := now.Truncate(time.Hour).Add(time.Hour).Sub(now)
log.Println("sleeping for", dur.Round(time.Second))
time.Sleep(dur)
}
func main() { func main() {
for { for {
stories, err := FetchHackerNewsTopStories() stories, err := FetchHackerNewsTopStories()
if err != nil { if err != nil {
SendErrorToDiscord(err) SendErrorToDiscord(err)
time.Sleep(time.Hour) WaitUntilNextHour()
continue continue
} }
@ -31,6 +38,6 @@ func main() {
} }
log.Println("Posting to SN ... OK") log.Println("Posting to SN ... OK")
} }
time.Sleep(time.Hour) WaitUntilNextHour()
} }
} }