Created
May 6, 2015 17:21
-
-
Save jiminoc/563ba071c63add787778 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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