Added a bit more logging, handle errors from Recipient.filterAndSendNotices(), factor in delta t for the interval
This commit is contained in:
parent
24f4aeca18
commit
b306a33f52
1 changed files with 15 additions and 4 deletions
17
main.go
17
main.go
|
@ -58,8 +58,10 @@ func main() {
|
||||||
}
|
}
|
||||||
// main loop
|
// main loop
|
||||||
for {
|
for {
|
||||||
|
t1 := time.Now().UnixMilli()
|
||||||
newNotices := []WidNotice{}
|
newNotices := []WidNotice{}
|
||||||
for _, a := range enabledApiEndpoints {
|
for _, a := range enabledApiEndpoints {
|
||||||
|
fmt.Printf("INFO\t%v Querying endpoint '%v' for new notices ...\n", time.Now().Format(time.RFC3339Nano), a.Id)
|
||||||
n, t, err := a.getNotices(persistent.data.(PersistentData).LastPublished[a.Id])
|
n, t, err := a.getNotices(persistent.data.(PersistentData).LastPublished[a.Id])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// retry
|
// retry
|
||||||
|
@ -74,10 +76,19 @@ func main() {
|
||||||
persistent.save()
|
persistent.save()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fmt.Println(newNotices)
|
if len(newNotices) > 0 {
|
||||||
for _, r := range config.Recipients {
|
for _, r := range config.Recipients {
|
||||||
r.filterAndSendNotices(newNotices, mailTemplate, mailAuth, config.SmtpConfiguration)
|
fmt.Printf("INFO\t%v Sending email notifications ...\n", time.Now().Format(time.RFC3339Nano))
|
||||||
|
err := r.filterAndSendNotices(newNotices, mailTemplate, mailAuth, config.SmtpConfiguration)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("ERROR\t%v\n", err)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("INFO\t%v Email notifications sent.\n", time.Now().Format(time.RFC3339Nano))
|
||||||
}
|
}
|
||||||
time.Sleep(time.Second * time.Duration(config.ApiFetchInterval))
|
}
|
||||||
|
}
|
||||||
|
t2 := time.Now().UnixMilli()
|
||||||
|
dt := int(t2 - t1)
|
||||||
|
time.Sleep(time.Millisecond * time.Duration((config.ApiFetchInterval * 1000) - dt))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue