add --no-cache flag #2

develop
Norwin 6 years ago
parent d8e6d642fc
commit bc542eb506

@ -117,6 +117,7 @@ var cfgFile string
func init() {
var (
debug bool
noCache bool
shouldNotify string
logFormat string
api string
@ -137,6 +138,7 @@ Notifications for failing checks are sent only once,
and then cached until the issue got resolved.
To clear the cache, delete the file ~/.osem_notify_cache.yaml.
`)
rootCmd.PersistentFlags().BoolVarP(&noCache, "no-cache", "", false, "send all notifications, ignoring results from previous runs. also don't update the cache.")
viper.BindPFlags(rootCmd.PersistentFlags()) // let flags override config

@ -64,7 +64,8 @@ func checkAndNotify(boxIds []string) error {
return fmt.Errorf("invalid value %s for \"notify\"", notify)
}
return results.SendNotifications(types)
useCache := !viper.GetBool("no-cache")
return results.SendNotifications(types, useCache)
}
return nil
}

@ -39,9 +39,10 @@ func (box Box) GetNotifier() (AbstractNotifier, error) {
return notifier.New(box.NotifyConf.Notifications.Options)
}
func (results BoxCheckResults) SendNotifications(notifyTypes []string) error {
// TODO: expose flag to not use cache
results = results.filterChangedFromCache()
func (results BoxCheckResults) SendNotifications(notifyTypes []string, useCache bool) error {
if useCache {
results = results.filterChangedFromCache()
}
toCheck := results.Size(notifyTypes)
if toCheck == 0 {
@ -90,11 +91,13 @@ func (results BoxCheckResults) SendNotifications(notifyTypes []string) error {
}
// update cache (with /all/ changed results to reset status)
notifyLog.Debug("updating cache")
cacheError := updateCache(box, resultsBox)
if cacheError != nil {
notifyLog.Error("could not cache notification results: ", cacheError)
errs = append(errs, cacheError.Error())
if useCache {
notifyLog.Debug("updating cache")
cacheError := updateCache(box, resultsBox)
if cacheError != nil {
notifyLog.Error("could not cache notification results: ", cacheError)
errs = append(errs, cacheError.Error())
}
}
if len(resultsDue) != 0 {

Loading…
Cancel
Save