Remove unnecessary goroutines

This commit is contained in:
ekzyis 2024-03-18 08:22:51 +01:00
parent 0285c5a53a
commit 7bf9e6c53c
1 changed files with 0 additions and 38 deletions

38
main.go
View File

@ -8,13 +8,6 @@ import (
"github.com/ekzyis/sn-goapi"
)
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 WaitUntilNextMinute() {
now := time.Now()
dur := now.Truncate(time.Minute).Add(time.Minute).Sub(now)
@ -29,35 +22,6 @@ func WaitUntilNextRun() {
time.Sleep(dur)
}
func CheckNotifications() {
var prevHasNewNotes bool
for {
log.Println("Checking notifications ...")
hasNewNotes, err := sn.CheckNotifications()
if err != nil {
SendErrorToDiscord(err)
} else {
if !prevHasNewNotes && hasNewNotes {
// only send embed on "rising edge"
SendNotificationsEmbedToDiscord()
log.Println("Forwarded notifications to monitoring")
} else if hasNewNotes {
log.Println("Notifications already forwarded")
}
}
prevHasNewNotes = hasNewNotes
WaitUntilNextRun()
}
}
func SessionKeepAlive() {
for {
log.Println("Refresh session using GET /api/auth/session ...")
sn.RefreshSession()
WaitUntilNextHour()
}
}
func SyncStories() {
for {
stories, err := FetchHackerNewsTopStories()
@ -78,8 +42,6 @@ func SyncStories() {
}
func main() {
go CheckNotifications()
go SessionKeepAlive()
go SyncStories()
for {
var (