File tree 1 file changed +8
-7
lines changed
1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package models
2
2
3
3
import (
4
4
"github.com/gocolly/colly"
5
+ log "github.com/sirupsen/logrus"
5
6
"strings"
6
7
)
7
8
@@ -38,19 +39,19 @@ func (handler *urlHandler) Handle(linkPath string) int {
38
39
return respStatus
39
40
}
40
41
41
- func (handler * urlHandler ) scrap (linkPath string , headFirst bool ) (int , error ) {
42
+ func (handler * urlHandler ) scrap (linkPath string , retry bool ) (int , error ) {
42
43
var err error
43
44
c := colly .NewCollector ()
44
45
respStatus := 0
45
46
c .OnResponse (func (resp * colly.Response ) {
46
47
respStatus = resp .StatusCode
47
48
})
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" )
54
55
err = c .Visit (linkPath )
55
56
}
56
57
return respStatus , err
You can’t perform that action at this time.
0 commit comments