From 57a4fabd506def6a9be960839466fce271771f58 Mon Sep 17 00:00:00 2001 From: Patrizio Bekerle Date: Tue, 17 Nov 2020 17:36:53 +0100 Subject: [PATCH] Introduce skip_first_allow_newest setting for RSS bee (#358) --- bees/rssbee/rssbee.go | 12 +++++++++++- bees/rssbee/rssbeefactory.go | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/bees/rssbee/rssbee.go b/bees/rssbee/rssbee.go index c80fdf66..d5047f4e 100644 --- a/bees/rssbee/rssbee.go +++ b/bees/rssbee/rssbee.go @@ -39,6 +39,9 @@ type RSSBee struct { // decides whether the next fetch should be skipped skipNextFetch bool + // decides whether only the newest item from the next fetch should to get through + skipNextFetchAllowNewest bool + eventChan chan bees.Event } @@ -47,7 +50,7 @@ func (mod *RSSBee) chanHandler(feed *rss.Feed, newchannels []*rss.Channel) { } func (mod *RSSBee) itemHandler(feed *rss.Feed, ch *rss.Channel, newitems []*rss.Item) { - if mod.skipNextFetch == true { + if mod.skipNextFetch == true || mod.skipNextFetchAllowNewest == true { mod.skipNextFetch = false return } @@ -130,6 +133,12 @@ func (mod *RSSBee) itemHandler(feed *rss.Feed, ch *rss.Channel, newitems []*rss. } mod.eventChan <- newitemEvent + + if mod.skipNextFetchAllowNewest == true { + // the first time only let the newest item pass + mod.skipNextFetchAllowNewest = false + break + } } mod.Logf("%d new item(s) in %s", len(newitems), feed.Url) } @@ -166,5 +175,6 @@ func (mod *RSSBee) ReloadOptions(options bees.BeeOptions) { mod.SetOptions(options) options.Bind("skip_first", &mod.skipNextFetch) + options.Bind("skip_first_allow_newest", &mod.skipNextFetchAllowNewest) options.Bind("url", &mod.url) } diff --git a/bees/rssbee/rssbeefactory.go b/bees/rssbee/rssbeefactory.go index f2f8ff44..10230cad 100644 --- a/bees/rssbee/rssbeefactory.go +++ b/bees/rssbee/rssbeefactory.go @@ -80,6 +80,13 @@ func (factory *RSSBeeFactory) Options() []bees.BeeOptionDescriptor { Mandatory: false, Default: false, }, + { + Name: "skip_first_allow_newest", + Description: "Whether to skip already existing entries, but allow the newest item to get through once", + Type: "bool", + Mandatory: false, + Default: false, + }, } return opts }