Wait until next full hour
This commit is contained in:
parent
5388480f31
commit
2a9b7c6737
11
main.go
11
main.go
|
@ -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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue