Archived
1
0
Fork 0

feat: anti-flapping

Send notifications only if the state duration is not instant. There are
a lot of replies with 0 seconds duration spamming channels.

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2021-07-07 15:36:03 +02:00
parent fbe5e5f723
commit 563d5ff9a6
No known key found for this signature in database
GPG key ID: FF42D23B580C89F7

20
main.go
View file

@ -340,16 +340,18 @@ func handleProducts(parser Parser, notifiers []Notifier, filters []Filter, db *g
} }
// send notifications // send notifications
if createThread { if duration > 0 {
for _, notifier := range notifiers { if createThread {
if err := notifier.NotifyWhenAvailable(shop.Name, dbProduct.Name, dbProduct.Price, dbProduct.PriceCurrency, dbProduct.URL); err != nil { for _, notifier := range notifiers {
log.Errorf("%s", err) if err := notifier.NotifyWhenAvailable(shop.Name, dbProduct.Name, dbProduct.Price, dbProduct.PriceCurrency, dbProduct.URL); err != nil {
log.Errorf("%s", err)
}
} }
} } else if closeThread {
} else if closeThread { for _, notifier := range notifiers {
for _, notifier := range notifiers { if err := notifier.NotifyWhenNotAvailable(dbProduct.URL, duration); err != nil {
if err := notifier.NotifyWhenNotAvailable(dbProduct.URL, duration); err != nil { log.Errorf("%s", err)
log.Errorf("%s", err) }
} }
} }
} }