mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-21 21:30:48 +02:00
feat(notifications): support delayed sending (#1142)
This commit is contained in:
parent
2fa8a2ad0c
commit
1d59fb83dd
6 changed files with 37 additions and 13 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
stdlog "log"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/containrrr/shoutrrr"
|
||||
"github.com/containrrr/shoutrrr/pkg/types"
|
||||
|
@ -77,14 +78,14 @@ func (n *shoutrrrTypeNotifier) GetNames() []string {
|
|||
return names
|
||||
}
|
||||
|
||||
func newShoutrrrNotifier(tplString string, acceptedLogLevels []log.Level, legacy bool, title string, urls ...string) t.Notifier {
|
||||
func newShoutrrrNotifier(tplString string, acceptedLogLevels []log.Level, legacy bool, title string, delay time.Duration, urls ...string) t.Notifier {
|
||||
|
||||
notifier := createNotifier(urls, acceptedLogLevels, tplString, legacy)
|
||||
notifier.params = &types.Params{"title": title}
|
||||
log.AddHook(notifier)
|
||||
|
||||
// Do the sending in a separate goroutine so we don't block the main process.
|
||||
go sendNotifications(notifier)
|
||||
go sendNotifications(notifier, delay)
|
||||
|
||||
return notifier
|
||||
}
|
||||
|
@ -112,8 +113,9 @@ func createNotifier(urls []string, levels []log.Level, tplString string, legacy
|
|||
}
|
||||
}
|
||||
|
||||
func sendNotifications(n *shoutrrrTypeNotifier) {
|
||||
func sendNotifications(n *shoutrrrTypeNotifier, delay time.Duration) {
|
||||
for msg := range n.messages {
|
||||
time.Sleep(delay)
|
||||
errs := n.Router.Send(msg, n.params)
|
||||
|
||||
for i, err := range errs {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue