Sync HN items every minute
This commit is contained in:
parent
a2633b1fdb
commit
0285c5a53a
31
main.go
31
main.go
|
@ -15,6 +15,13 @@ func WaitUntilNextHour() {
|
||||||
time.Sleep(dur)
|
time.Sleep(dur)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
func WaitUntilNextRun() {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
dur := now.Truncate(time.Minute).Add(15 * time.Minute).Sub(now)
|
dur := now.Truncate(time.Minute).Add(15 * time.Minute).Sub(now)
|
||||||
|
@ -51,25 +58,35 @@ func SessionKeepAlive() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func SyncStories() {
|
||||||
go CheckNotifications()
|
|
||||||
go SessionKeepAlive()
|
|
||||||
for {
|
for {
|
||||||
|
|
||||||
stories, err := FetchHackerNewsTopStories()
|
stories, err := FetchHackerNewsTopStories()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
SendErrorToDiscord(err)
|
SendErrorToDiscord(err)
|
||||||
WaitUntilNextRun()
|
WaitUntilNextMinute()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := SaveStories(&stories); err != nil {
|
if err := SaveStories(&stories); err != nil {
|
||||||
SendErrorToDiscord(err)
|
SendErrorToDiscord(err)
|
||||||
WaitUntilNextRun()
|
WaitUntilNextMinute()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var filtered *[]Story
|
WaitUntilNextMinute()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
go CheckNotifications()
|
||||||
|
go SessionKeepAlive()
|
||||||
|
go SyncStories()
|
||||||
|
for {
|
||||||
|
var (
|
||||||
|
filtered *[]Story
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
if filtered, err = CurateContentForStackerNews(); err != nil {
|
if filtered, err = CurateContentForStackerNews(); err != nil {
|
||||||
SendErrorToDiscord(err)
|
SendErrorToDiscord(err)
|
||||||
WaitUntilNextRun()
|
WaitUntilNextRun()
|
||||||
|
|
Loading…
Reference in New Issue