Skip to content

Commit ed82d00

Browse files
committed
fix retry mechanism
1 parent c34686b commit ed82d00

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

models/url_handler.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package models
22

33
import (
44
"github.com/gocolly/colly"
5+
log "github.com/sirupsen/logrus"
56
"strings"
67
)
78

@@ -38,19 +39,19 @@ func (handler *urlHandler) Handle(linkPath string) int {
3839
return respStatus
3940
}
4041

41-
func (handler *urlHandler) scrap(linkPath string, headFirst bool) (int, error) {
42+
func (handler *urlHandler) scrap(linkPath string, retry bool) (int, error) {
4243
var err error
4344
c := colly.NewCollector()
4445
respStatus := 0
4546
c.OnResponse(func(resp *colly.Response) {
4647
respStatus = resp.StatusCode
4748
})
48-
if headFirst {
49-
c.CheckHead = true
50-
err = c.Visit(linkPath)
51-
}
52-
if err != nil || respStatus == 0 {
53-
c.CheckHead = false
49+
err = c.Visit(linkPath)
50+
if retry && (err != nil || respStatus == 0) {
51+
log.WithFields(log.Fields{
52+
"link": linkPath,
53+
"error": err,
54+
}).Error("Failed get URL data, retrying")
5455
err = c.Visit(linkPath)
5556
}
5657
return respStatus, err

0 commit comments

Comments
 (0)