From a3933b48c63e5616f16135797c39d54ff64304c1 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Mon, 18 Mar 2024 07:09:17 +0100 Subject: [PATCH] Only run every 15 minutes This should prevent spam fees. --- main.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 3d03898..de005f9 100644 --- a/main.go +++ b/main.go @@ -15,9 +15,9 @@ func WaitUntilNextHour() { time.Sleep(dur) } -func WaitUntilNextMinute() { +func WaitUntilNextRun() { now := time.Now() - dur := now.Truncate(time.Minute).Add(time.Minute).Sub(now) + dur := now.Truncate(time.Minute).Add(15 * time.Minute).Sub(now) log.Println("sleeping for", dur.Round(time.Second)) time.Sleep(dur) } @@ -39,7 +39,7 @@ func CheckNotifications() { } } prevHasNewNotes = hasNewNotes - WaitUntilNextMinute() + WaitUntilNextRun() } } @@ -59,20 +59,20 @@ func main() { stories, err := FetchHackerNewsTopStories() if err != nil { SendErrorToDiscord(err) - WaitUntilNextMinute() + WaitUntilNextRun() continue } if err := SaveStories(&stories); err != nil { SendErrorToDiscord(err) - WaitUntilNextMinute() + WaitUntilNextRun() continue } var filtered *[]Story if filtered, err = CurateContentForStackerNews(); err != nil { SendErrorToDiscord(err) - WaitUntilNextMinute() + WaitUntilNextRun() continue } @@ -94,6 +94,6 @@ func main() { continue } } - WaitUntilNextMinute() + WaitUntilNextRun() } }