small pixel drawing of a pufferfish vore

doth a global timeout worky?
Jes Olson j3s@c3f.net
Wed, 14 Aug 2024 14:02:00 -0400
commit

402580307480a30b40be299f0b0d3581a88b06ef

parent

6fa755bde1710c8111980c98923b12caaf3074e3

2 files changed, 6 insertions(+), 19 deletions(-)

jump to
M reaper/reaper.goreaper/reaper.go

@@ -1,7 +1,6 @@

package reaper import ( - "context" "errors" "log" "runtime"

@@ -106,15 +105,8 @@

// refreshFeed triggers a fetch on the given feed, // and sets a fetch error in the db if there is one. func (r *Reaper) refreshFeed(f *rss.Feed) { - // 20 seccy timeout - ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) - defer cancel() - - err := f.Update(ctx) + err := f.Update() if err != nil { - if ctx.Err() == context.DeadlineExceeded { - log.Printf("reaper: %s timed out after 20 seconds", f.UpdateURL) - } r.handleFeedFetchFailure(f.UpdateURL, err) } }
M rss/rss.gorss/rss.go

@@ -2,7 +2,6 @@ package rss

import ( "bytes" - "context" "errors" "fmt" "io"

@@ -41,6 +40,7 @@

// DefaultFetchFunc uses http.DefaultClient to fetch a feed. var DefaultFetchFunc = func(url string) (resp *http.Response, err error) { client := http.DefaultClient + client.Timeout = 20 * time.Second return client.Get(url) }

@@ -135,16 +135,11 @@ // The default value is 12 hours.

var DefaultRefreshInterval = 12 * time.Hour // Update fetches any new items and updates f. -func (f *Feed) Update(ctx context.Context) error { - select { - case <-ctx.Done(): - return ctx.Err() // Return the context error if it was canceled or timed out - default: - if f.FetchFunc == nil { - f.FetchFunc = DefaultFetchFunc - } - return f.UpdateByFunc(f.FetchFunc) +func (f *Feed) Update() error { + if f.FetchFunc == nil { + f.FetchFunc = DefaultFetchFunc } + return f.UpdateByFunc(f.FetchFunc) } // UpdateByFunc uses a func to update f.