diff options
Diffstat (limited to 'src/wikiarticle.go')
| -rw-r--r-- | src/wikiarticle.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/wikiarticle.go b/src/wikiarticle.go index c1ce486..5f7aaa1 100644 --- a/src/wikiarticle.go +++ b/src/wikiarticle.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io" - "log" "net/http" "net/url" "strconv" @@ -39,10 +38,11 @@ func (a *App) queryWikiArticle(name string) (wikiArticleEntry, int, error) { var resp *http.Response var err error + start := time.Now() for attempt := 0; attempt < 5; attempt++ { if attempt > 0 { backoff := 1 << attempt - log.Printf("retry %d/%d for %s after %ds backoff", attempt, 4, name, backoff) + logHTTPRetry(attempt, 4, backoff, name) time.Sleep(time.Duration(backoff) * time.Second) } @@ -59,15 +59,18 @@ func (a *App) queryWikiArticle(name string) (wikiArticleEntry, int, error) { if resp.StatusCode != http.StatusOK { body, _ := io.ReadAll(io.LimitReader(resp.Body, 2048)) resp.Body.Close() + logHTTPRequest("GET", reqURL, resp.StatusCode, time.Since(start).Seconds()) return wikiArticleEntry{}, resp.StatusCode, fmt.Errorf("HTTP %d: %s", resp.StatusCode, body) } break } if err != nil { + logHTTPRequest("GET", reqURL, 0, time.Since(start).Seconds()) return wikiArticleEntry{}, 0, fmt.Errorf("http get: %w", err) } defer resp.Body.Close() + logHTTPRequest("GET", reqURL, resp.StatusCode, time.Since(start).Seconds()) var articles []map[string]interface{} if err := json.NewDecoder(resp.Body).Decode(&articles); err != nil { |
