mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
feat(feed): Configurable request timeout (#456)
* feat(feed): Add field for setting request timeout * fix: missing type in interface * feat: add postgres migration and column to base schema
This commit is contained in:
parent
47eaeaa635
commit
72be86a34f
10 changed files with 42 additions and 14 deletions
|
@ -21,6 +21,7 @@ type RSSJob struct {
|
|||
URL string
|
||||
Repo domain.FeedCacheRepo
|
||||
ReleaseSvc release.Service
|
||||
Timeout time.Duration
|
||||
|
||||
attempts int
|
||||
errors []error
|
||||
|
@ -28,7 +29,7 @@ type RSSJob struct {
|
|||
JobID int
|
||||
}
|
||||
|
||||
func NewRSSJob(name string, indexerIdentifier string, log zerolog.Logger, url string, repo domain.FeedCacheRepo, releaseSvc release.Service) *RSSJob {
|
||||
func NewRSSJob(name string, indexerIdentifier string, log zerolog.Logger, url string, repo domain.FeedCacheRepo, releaseSvc release.Service, timeout time.Duration) *RSSJob {
|
||||
return &RSSJob{
|
||||
Name: name,
|
||||
IndexerIdentifier: indexerIdentifier,
|
||||
|
@ -36,6 +37,7 @@ func NewRSSJob(name string, indexerIdentifier string, log zerolog.Logger, url st
|
|||
URL: url,
|
||||
Repo: repo,
|
||||
ReleaseSvc: releaseSvc,
|
||||
Timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,7 +142,7 @@ func (j *RSSJob) processItem(item *gofeed.Item) *domain.Release {
|
|||
}
|
||||
|
||||
func (j *RSSJob) getFeed() (items []*gofeed.Item, err error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), j.Timeout)
|
||||
defer cancel()
|
||||
|
||||
feed, err := gofeed.NewParser().ParseURLWithContext(j.URL, ctx) // there's an RSS specific parser as well.
|
||||
|
|
|
@ -35,6 +35,7 @@ type feedInstance struct {
|
|||
ApiKey string
|
||||
Implementation string
|
||||
CronSchedule time.Duration
|
||||
Timeout time.Duration
|
||||
}
|
||||
|
||||
type service struct {
|
||||
|
@ -300,6 +301,7 @@ func (s *service) startJob(f domain.Feed) error {
|
|||
URL: f.URL,
|
||||
ApiKey: f.ApiKey,
|
||||
CronSchedule: time.Duration(f.Interval) * time.Minute,
|
||||
Timeout: time.Duration(f.Timeout) * time.Second,
|
||||
}
|
||||
|
||||
switch fi.Implementation {
|
||||
|
@ -330,7 +332,7 @@ func (s *service) addTorznabJob(f feedInstance) error {
|
|||
l := s.log.With().Str("feed", f.Name).Logger()
|
||||
|
||||
// setup torznab Client
|
||||
c := torznab.NewClient(torznab.Config{Host: f.URL, ApiKey: f.ApiKey})
|
||||
c := torznab.NewClient(torznab.Config{Host: f.URL, ApiKey: f.ApiKey, Timeout: f.Timeout})
|
||||
|
||||
// create job
|
||||
job := NewTorznabJob(f.Name, f.IndexerIdentifier, l, f.URL, c, s.cacheRepo, s.releaseSvc)
|
||||
|
@ -373,7 +375,7 @@ func (s *service) addRSSJob(f feedInstance) error {
|
|||
l := s.log.With().Str("feed", f.Name).Logger()
|
||||
|
||||
// create job
|
||||
job := NewRSSJob(f.Name, f.IndexerIdentifier, l, f.URL, s.cacheRepo, s.releaseSvc)
|
||||
job := NewRSSJob(f.Name, f.IndexerIdentifier, l, f.URL, s.cacheRepo, s.releaseSvc, f.Timeout)
|
||||
|
||||
// schedule job
|
||||
id, err := s.scheduler.AddJob(job, f.CronSchedule, f.IndexerIdentifier)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue