Skip to content

Commit

Permalink
Allow sleeping between feed-fetches.
Browse files Browse the repository at this point in the history
Added support for a per-feed `sleep` setting, which can force a sleep
after making a feed-request.

This was inspired by #83.
  • Loading branch information
skx committed Mar 13, 2022
1 parent 033511d commit ff4fd6e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions config_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ include-title | Include only items with title matching the given regular-express
notify | Comma-delimited list of emails to send notifications to (if set,
| replaces the emails set in the cron/daemon command).
retry | The maximum number of times to retry a failing HTTP-fetch.
sleep | Sleep the specified number of seconds, after making the request.
template | The path to a feed-specific email template to use.
user-agent | Configure a specific User-Agent when making HTTP requests.
Expand Down
23 changes: 23 additions & 0 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ package processor
import (
"fmt"
"regexp"
"strconv"
"strings"
"time"

"github.com/k3a/html2text"
"github.com/skx/rss2email/configfile"
Expand Down Expand Up @@ -67,6 +69,9 @@ func (p *Processor) ProcessFeeds(recipients []string) []error {
// we'll prefer if available.
feedRecipients := recipients

// Should we sleep after getting this feed?
sleep := 0

// For each option
for _, opt := range entry.Options {

Expand All @@ -81,13 +86,31 @@ func (p *Processor) ProcessFeeds(recipients []string) []error {
feedRecipients[i] = strings.TrimSpace(feedRecipients[i])
}
}

// Sleep setting?
if opt.Name == "sleep" {

// Convert the value, and if there was
// no error save it away.
num, err := strconv.Atoi(opt.Value)
if err != nil {
fmt.Printf("WARNING: %s:%s - failed to parse as sleep-delay %s\n", opt.Name, opt.Value, err.Error())
} else {
sleep = num
}
}
}

// Process this specific entry.
err := p.processFeed(entry, feedRecipients)
if err != nil {
errors = append(errors, fmt.Errorf("error processing %s - %s", entry.URL, err))
}

// If we're supposed to sleep, do so
if sleep != 0 {
time.Sleep(time.Duration(sleep) * time.Second)
}
}

// Prune old state files, unless we saw an error.
Expand Down

0 comments on commit ff4fd6e

Please sign in to comment.