From 2a9b7c6737db85a9e6f5bf58777ea0424935bbc7 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Thu, 27 Apr 2023 00:41:57 +0200 Subject: [PATCH] Wait until next full hour --- main.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index dca847f..8a4f3d3 100644 --- a/main.go +++ b/main.go @@ -6,13 +6,20 @@ import ( "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() { for { stories, err := FetchHackerNewsTopStories() if err != nil { SendErrorToDiscord(err) - time.Sleep(time.Hour) + WaitUntilNextHour() continue } @@ -31,6 +38,6 @@ func main() { } log.Println("Posting to SN ... OK") } - time.Sleep(time.Hour) + WaitUntilNextHour() } }