refactor: http retry for retryable errors (#20)
This commit is contained in:
16
rss/job.go
16
rss/job.go
@@ -3,6 +3,7 @@ package rss
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/l3uddz/nabarr/cmd/nabarr/pvr"
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
"github.com/robfig/cron/v3"
|
||||
"time"
|
||||
)
|
||||
@@ -17,13 +18,18 @@ func (c *Client) AddJob(feed feedItem) error {
|
||||
feed.CacheDuration = (24 * time.Hour) * 28
|
||||
}
|
||||
|
||||
l := c.log.With().
|
||||
Str("feed_name", feed.Name).
|
||||
Logger()
|
||||
|
||||
// create job
|
||||
job := &rssJob{
|
||||
name: feed.Name,
|
||||
log: c.log.With().Str("feed_name", feed.Name).Logger(),
|
||||
url: feed.URL,
|
||||
timeout: 30 * time.Second,
|
||||
pvrs: make(map[string]pvr.PVR, 0),
|
||||
name: feed.Name,
|
||||
log: l,
|
||||
http: util.NewRetryableHttpClient(30*time.Second, nil, &l),
|
||||
|
||||
url: feed.URL,
|
||||
pvrs: make(map[string]pvr.PVR, 0),
|
||||
|
||||
attempts: 0,
|
||||
errors: make([]error, 0),
|
||||
|
||||
@@ -48,7 +48,7 @@ func (j *rssJob) queueItemWithPvrs(item *media.FeedItem) {
|
||||
|
||||
func (j *rssJob) getFeed() ([]media.FeedItem, error) {
|
||||
// request feed
|
||||
res, err := rek.Get(j.url, rek.Timeout(j.timeout))
|
||||
res, err := rek.Get(j.url, rek.Client(j.http))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("request feed: %w", err)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/l3uddz/nabarr/cmd/nabarr/pvr"
|
||||
"github.com/robfig/cron/v3"
|
||||
"github.com/rs/zerolog"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -23,11 +24,12 @@ type Config struct {
|
||||
}
|
||||
|
||||
type rssJob struct {
|
||||
name string
|
||||
log zerolog.Logger
|
||||
url string
|
||||
timeout time.Duration
|
||||
pvrs map[string]pvr.PVR
|
||||
name string
|
||||
log zerolog.Logger
|
||||
http *http.Client
|
||||
|
||||
url string
|
||||
pvrs map[string]pvr.PVR
|
||||
|
||||
attempts int
|
||||
errors []error
|
||||
|
||||
Reference in New Issue
Block a user