Skip to content

Instantly share code, notes, and snippets.

@jiminoc
Created May 6, 2015 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiminoc/563ba071c63add787778 to your computer and use it in GitHub Desktop.
Save jiminoc/563ba071c63add787778 to your computer and use it in GitHub Desktop.
// check to see if we've already sent this alert recently
func alreadySentRecently(res reservation) bool {
timeNow := time.Now().UTC()
mapKey := res.App + res.Component
waitForNotifyTime := time.Duration(cfg.Main.HoursBetweenAlerts) * time.Hour
_, ok := sentAlerts[mapKey]
if !ok {
sentAlerts[mapKey] = timeNow
l.info("Sending new alert for [%s/%s]", res.App, res.Component)
return false
}
// check to see if the time elapsed goes over our threshold
duration := timeNow.Sub(sentAlerts[mapKey])
if duration >= waitForNotifyTime {
sentAlerts[mapKey] = timeNow
l.info("Sent alert already but duration ran out [%s/%s]", res.App, res.Component)
return false
}
l.info("Already sent alert for [%s/%s]", res.App, res.Component)
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment