From 1416550be9652d2ed64244eb4edae062945ffe93 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Mon, 18 Mar 2024 08:24:54 +0100 Subject: [PATCH] First wait, then run --- main.go | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/main.go b/main.go index 01291fa..73f9d04 100644 --- a/main.go +++ b/main.go @@ -8,36 +8,22 @@ import ( "github.com/ekzyis/sn-goapi" ) -func WaitUntilNextMinute() { - now := time.Now() - dur := now.Truncate(time.Minute).Add(time.Minute).Sub(now) - log.Println("sleeping for", dur.Round(time.Second)) - time.Sleep(dur) -} - -func WaitUntilNextRun() { - now := time.Now() - dur := now.Truncate(time.Minute).Add(15 * time.Minute).Sub(now) - log.Println("sleeping for", dur.Round(time.Second)) - time.Sleep(dur) -} - func SyncStories() { for { + now := time.Now() + dur := now.Truncate(time.Minute).Add(time.Minute).Sub(now) + log.Println("[hn] sleeping for", dur.Round(time.Second)) + time.Sleep(dur) + stories, err := FetchHackerNewsTopStories() if err != nil { SendErrorToDiscord(err) - WaitUntilNextMinute() continue } - if err := SaveStories(&stories); err != nil { SendErrorToDiscord(err) - WaitUntilNextMinute() continue } - - WaitUntilNextMinute() } } @@ -49,9 +35,13 @@ func main() { err error ) + now := time.Now() + dur := now.Truncate(time.Minute).Add(15 * time.Minute).Sub(now) + log.Println("[sn] sleeping for", dur.Round(time.Second)) + time.Sleep(dur) + if filtered, err = CurateContentForStackerNews(); err != nil { SendErrorToDiscord(err) - WaitUntilNextRun() continue } @@ -73,6 +63,5 @@ func main() { continue } } - WaitUntilNextRun() } }