mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-14 06:06:38 +01:00
feat(notifications): add general notification delay (#1246)
This commit is contained in:
parent
f79e4b5435
commit
a5c60a9fe6
4 changed files with 91 additions and 12 deletions
|
|
@ -45,7 +45,7 @@ func AppendLegacyUrls(urls []string, cmd *cobra.Command, title string) ([]string
|
|||
log.WithError(err).Fatal("could not read notifications argument")
|
||||
}
|
||||
|
||||
delay := time.Duration(0)
|
||||
legacyDelay := time.Duration(0)
|
||||
|
||||
for _, t := range types {
|
||||
|
||||
|
|
@ -76,14 +76,29 @@ func AppendLegacyUrls(urls []string, cmd *cobra.Command, title string) ([]string
|
|||
urls = append(urls, shoutrrrURL)
|
||||
|
||||
if delayNotifier, ok := legacyNotifier.(ty.DelayNotifier); ok {
|
||||
delay = delayNotifier.GetDelay()
|
||||
legacyDelay = delayNotifier.GetDelay()
|
||||
}
|
||||
|
||||
log.WithField("URL", shoutrrrURL).Trace("created Shoutrrr URL from legacy notifier")
|
||||
}
|
||||
|
||||
delay := GetDelay(cmd, legacyDelay)
|
||||
return urls, delay
|
||||
}
|
||||
|
||||
// GetDelay returns the legacy delay if defined, otherwise the delay as set by args is returned
|
||||
func GetDelay(c *cobra.Command, legacyDelay time.Duration) time.Duration {
|
||||
if legacyDelay > 0 {
|
||||
return legacyDelay
|
||||
}
|
||||
|
||||
delay, _ := c.PersistentFlags().GetInt("notifications-delay")
|
||||
if delay > 0 {
|
||||
return time.Duration(delay) * time.Second
|
||||
}
|
||||
return time.Duration(0)
|
||||
}
|
||||
|
||||
// GetTitle returns a common notification title with hostname appended
|
||||
func GetTitle(hostname string) string {
|
||||
title := "Watchtower updates"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue