Skip to content

Commit

Permalink
Changes to cron scheduler, adding logging for errors in alert task, u…
Browse files Browse the repository at this point in the history
…pdating alert email
  • Loading branch information
Danzabar committed Nov 2, 2016
1 parent aac399a commit 4807112
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions alert_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func sendMail(t string, n []Notification, a []AlertGroup) {
// We don't want to update the notifications
// but we also don't want to kill the server
// with a panic.
log.Fatal(err)
log.Print(err)
return
}
}
Expand All @@ -99,7 +99,7 @@ func createEmailBody(n []Notification, t string) string {
buf.WriteString(fmt.Sprintf("<html><div><p>New notifications for the tag %s</p><ul>", t))

for _, v := range n {
buf.WriteString(fmt.Sprintf("<li>%s</li>", v.Message))
buf.WriteString(fmt.Sprintf("<li>%s (%s)- %s</li>", v.Message, v.Source, v.Action))
}

buf.WriteString("</ul><p>Do not reply to this email</p></div></html>")
Expand All @@ -112,6 +112,7 @@ func skipNotifications(n []Notification) {
for _, v := range n {
v.Read = true
if err := tx.Save(v).Error; err != nil {
log.Print(err)
tx.Rollback()
}
}
Expand All @@ -125,6 +126,7 @@ func updateNotifications(n []Notification) {
for _, v := range n {
v.Alerted = true
if err := tx.Save(&v).Error; err != nil {
log.Print(err)
tx.Rollback()
}
}
Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ func main() {
dbDriver := flag.String("driver", "sqlite3", "The database driver notify should use")
dbCreds := flag.String("creds", "/tmp/main.db", "The database credentials")
enableAlert := flag.Bool("a", false, "Enables the alerting schedule")
port := flag.String("port", ":8080", "Port on which the server runs")

flag.Parse()

App = NewApp(":8080", *dbDriver, *dbCreds)
App = NewApp(*port, *dbDriver, *dbCreds)

// Run Migrations
if *migrate {
Expand All @@ -31,7 +32,7 @@ func main() {

// Start the alert task schedule
if *enableAlert {
gocron.Every(5).Minutes().Do(SendAlerts)
gocron.Every(1).Minute().Do(SendAlerts)
<-gocron.Start()
}

Expand Down

0 comments on commit 4807112

Please sign in to comment.