Skip to content

Commit

Permalink
Introduce skip_first_allow_newest setting for RSS bee (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbek authored Nov 17, 2020
1 parent 3dbb1f6 commit 57a4fab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 11 additions & 1 deletion bees/rssbee/rssbee.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
7 changes: 7 additions & 0 deletions bees/rssbee/rssbeefactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 57a4fab

Please sign in to comment.