Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds HTTP response timeout configuration #126

Merged
merged 2 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ youtube: # youtube configuration, optional

system: # system configuration
update: 1m # update interval for checking source feeds
http_response_timeout: 30s # http response timeout
max_per_feed: 10 # max items per feed to be processed and inclueded in the final RSS
max_total: 50 # max total items to be included in the final RSS
max_keep: 1000 # max items to be kept in the internal database
Expand Down
2 changes: 1 addition & 1 deletion app/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (s *Server) Run(ctx context.Context, port int) {
Addr: fmt.Sprintf(":%d", port),
Handler: s.router(),
ReadHeaderTimeout: 5 * time.Second,
Copy link
Owner

@umputun umputun Apr 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably all of the timeouts can be made configurable, not just this one.

WriteTimeout: 30 * time.Second,
WriteTimeout: s.Conf.System.HttpResponseTimeout,
IdleTimeout: 30 * time.Second,
}
serverLock.Unlock()
Expand Down
16 changes: 10 additions & 6 deletions app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import (
type Conf struct {
Feeds map[string]Feed `yaml:"feeds"`
System struct {
UpdateInterval time.Duration `yaml:"update"`
MaxItems int `yaml:"max_per_feed"`
MaxTotal int `yaml:"max_total"`
MaxKeepInDB int `yaml:"max_keep"`
Concurrent int `yaml:"concurrent"`
BaseURL string `yaml:"base_url"`
UpdateInterval time.Duration `yaml:"update"`
HttpResponseTimeout time.Duration `yaml:"http_response_timeout"`
MaxItems int `yaml:"max_per_feed"`
MaxTotal int `yaml:"max_total"`
MaxKeepInDB int `yaml:"max_keep"`
Concurrent int `yaml:"concurrent"`
BaseURL string `yaml:"base_url"`
} `yaml:"system"`

YouTube struct {
Expand Down Expand Up @@ -138,6 +139,9 @@ func (c *Conf) setDefaults() {
if c.System.UpdateInterval == 0 {
c.System.UpdateInterval = time.Minute * 5
}
if c.System.HttpResponseTimeout == 0 {
c.System.HttpResponseTimeout = time.Second * 30
}

// set default values for feeds
for k, f := range c.Feeds {
Expand Down
24 changes: 17 additions & 7 deletions app/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestLoad(t *testing.T) {
assert.Equal(t, "https://bbb.com/u1", r.Feeds["second"].Sources[0].URL)
assert.Equal(t, "^filterme*", r.Feeds["filtered"].Filter.Title)
assert.Equal(t, time.Second*600, r.System.UpdateInterval)
assert.Equal(t, time.Second*10, r.System.HttpResponseTimeout)
assert.Equal(t, []ytfdeed.FeedInfo{{Name: "name1", ID: "id1", Type: "playlist", Keep: 15},
{Name: "name2", ID: "id2", Type: "channel", Language: "ru-ru", Keep: 5}},
r.YouTube.Channels, "2 yt")
Expand Down Expand Up @@ -90,13 +91,22 @@ func TestSetDefault(t *testing.T) {

expectedConf := Conf{
System: struct {
UpdateInterval time.Duration `yaml:"update"`
MaxItems int `yaml:"max_per_feed"`
MaxTotal int `yaml:"max_total"`
MaxKeepInDB int `yaml:"max_keep"`
Concurrent int `yaml:"concurrent"`
BaseURL string `yaml:"base_url"`
}{UpdateInterval: time.Minute * 5, MaxItems: 5, MaxTotal: 100, MaxKeepInDB: 5000, Concurrent: 8, BaseURL: ""},
UpdateInterval time.Duration `yaml:"update"`
HttpResponseTimeout time.Duration `yaml:"http_response_timeout"`
MaxItems int `yaml:"max_per_feed"`
MaxTotal int `yaml:"max_total"`
MaxKeepInDB int `yaml:"max_keep"`
Concurrent int `yaml:"concurrent"`
BaseURL string `yaml:"base_url"`
}{
UpdateInterval: time.Minute * 5,
HttpResponseTimeout: time.Second * 30,
MaxItems: 5,
MaxTotal: 100,
MaxKeepInDB: 5000,
Concurrent: 8,
BaseURL: "",
},
}

assert.Equal(t, expectedConf.System, c.System)
Expand Down
1 change: 1 addition & 0 deletions app/config/testdata/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ feeds:
owner_email: "blah@example.com"
system:
update: 600s
http_response_timeout: 10s

youtube:
dl_template: yt-dlp --extract-audio --audio-format=mp3 -f m4a/bestaudio "https://www.youtube.com/watch?v={{.ID}}" --no-progress -o {{.Filename}}
Expand Down
78 changes: 42 additions & 36 deletions app/proc/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,21 @@ func TestProcessor_DoRemoveOldItems(t *testing.T) {
},
},
System: struct {
UpdateInterval time.Duration `yaml:"update"`
MaxItems int `yaml:"max_per_feed"`
MaxTotal int `yaml:"max_total"`
MaxKeepInDB int `yaml:"max_keep"`
Concurrent int `yaml:"concurrent"`
BaseURL string `yaml:"base_url"`
UpdateInterval time.Duration `yaml:"update"`
HttpResponseTimeout time.Duration `yaml:"http_response_timeout"`
MaxItems int `yaml:"max_per_feed"`
MaxTotal int `yaml:"max_total"`
MaxKeepInDB int `yaml:"max_keep"`
Concurrent int `yaml:"concurrent"`
BaseURL string `yaml:"base_url"`
}{
UpdateInterval: time.Second / 2,
MaxItems: 5,
MaxTotal: 5,
MaxKeepInDB: 5,
Concurrent: 1,
BaseURL: "baseUrl",
UpdateInterval: time.Second / 2,
HttpResponseTimeout: time.Second,
MaxItems: 5,
MaxTotal: 5,
MaxKeepInDB: 5,
Concurrent: 1,
BaseURL: "baseUrl",
},
YouTube: struct {
DlTemplate string `yaml:"dl_template"`
Expand Down Expand Up @@ -202,19 +204,21 @@ func TestProcessor_DoLoadMaxItems(t *testing.T) {
},
},
System: struct {
UpdateInterval time.Duration `yaml:"update"`
MaxItems int `yaml:"max_per_feed"`
MaxTotal int `yaml:"max_total"`
MaxKeepInDB int `yaml:"max_keep"`
Concurrent int `yaml:"concurrent"`
BaseURL string `yaml:"base_url"`
UpdateInterval time.Duration `yaml:"update"`
HttpResponseTimeout time.Duration `yaml:"http_response_timeout"`
MaxItems int `yaml:"max_per_feed"`
MaxTotal int `yaml:"max_total"`
MaxKeepInDB int `yaml:"max_keep"`
Concurrent int `yaml:"concurrent"`
BaseURL string `yaml:"base_url"`
}{
UpdateInterval: time.Second / 2,
MaxItems: 3,
MaxTotal: 5,
MaxKeepInDB: 5,
Concurrent: 1,
BaseURL: "baseUrl",
UpdateInterval: time.Second / 2,
HttpResponseTimeout: time.Second,
MaxItems: 3,
MaxTotal: 5,
MaxKeepInDB: 5,
Concurrent: 1,
BaseURL: "baseUrl",
},
YouTube: struct {
DlTemplate string `yaml:"dl_template"`
Expand Down Expand Up @@ -300,19 +304,21 @@ func TestProcessor_DoSkipItems(t *testing.T) {
},
},
System: struct {
UpdateInterval time.Duration `yaml:"update"`
MaxItems int `yaml:"max_per_feed"`
MaxTotal int `yaml:"max_total"`
MaxKeepInDB int `yaml:"max_keep"`
Concurrent int `yaml:"concurrent"`
BaseURL string `yaml:"base_url"`
UpdateInterval time.Duration `yaml:"update"`
HttpResponseTimeout time.Duration `yaml:"http_response_timeout"`
MaxItems int `yaml:"max_per_feed"`
MaxTotal int `yaml:"max_total"`
MaxKeepInDB int `yaml:"max_keep"`
Concurrent int `yaml:"concurrent"`
BaseURL string `yaml:"base_url"`
}{
UpdateInterval: time.Second / 2,
MaxItems: 10,
MaxTotal: 10,
MaxKeepInDB: 10,
Concurrent: 1,
BaseURL: "baseUrl",
UpdateInterval: time.Second / 2,
HttpResponseTimeout: time.Second,
MaxItems: 10,
MaxTotal: 10,
MaxKeepInDB: 10,
Concurrent: 1,
BaseURL: "baseUrl",
},
YouTube: struct {
DlTemplate string `yaml:"dl_template"`
Expand Down
Loading