mirror of
https://github.com/terorie/od-database-crawler.git
synced 2025-04-19 18:36:43 +00:00
Don't retry on 401/403
This commit is contained in:
parent
faad19f121
commit
ab5874129f
@ -18,6 +18,7 @@ import (
|
|||||||
|
|
||||||
var client fasthttp.Client
|
var client fasthttp.Client
|
||||||
var ErrRateLimit = errors.New("too many requests")
|
var ErrRateLimit = errors.New("too many requests")
|
||||||
|
var ErrForbidden = errors.New("access denied")
|
||||||
|
|
||||||
type RemoteDir struct {
|
type RemoteDir struct {
|
||||||
Wait sync.WaitGroup
|
Wait sync.WaitGroup
|
||||||
@ -48,16 +49,8 @@ func GetDir(j *Job, f *File) (links []url.URL, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch res.StatusCode() {
|
err = checkStatusCode(res.StatusCode())
|
||||||
case fasthttp.StatusOK:
|
if err != nil { return }
|
||||||
break
|
|
||||||
|
|
||||||
case fasthttp.StatusTooManyRequests:
|
|
||||||
return nil, ErrRateLimit
|
|
||||||
|
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("got HTTP status %d", res.StatusCode())
|
|
||||||
}
|
|
||||||
|
|
||||||
body := res.Body()
|
body := res.Body()
|
||||||
doc := html.NewTokenizer(bytes.NewReader(body))
|
doc := html.NewTokenizer(bytes.NewReader(body))
|
||||||
@ -155,16 +148,8 @@ func GetFile(u url.URL, f *File) (err error) {
|
|||||||
|
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
switch res.StatusCode() {
|
err = checkStatusCode(res.StatusCode())
|
||||||
case fasthttp.StatusOK:
|
if err != nil { return }
|
||||||
break
|
|
||||||
|
|
||||||
case fasthttp.StatusTooManyRequests:
|
|
||||||
return ErrRateLimit
|
|
||||||
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("got HTTP status %d", res.StatusCode())
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO Inefficient af
|
// TODO Inefficient af
|
||||||
header := res.Header.Header()
|
header := res.Header.Header()
|
||||||
@ -233,6 +218,23 @@ func (f *File) applyHeader(k, v string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkStatusCode(status int) error {
|
||||||
|
switch status {
|
||||||
|
case fasthttp.StatusOK:
|
||||||
|
return nil
|
||||||
|
|
||||||
|
case fasthttp.StatusTooManyRequests:
|
||||||
|
return ErrRateLimit
|
||||||
|
|
||||||
|
case fasthttp.StatusForbidden,
|
||||||
|
fasthttp.StatusUnauthorized:
|
||||||
|
return ErrForbidden
|
||||||
|
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("got HTTP status %d", status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var urlBlackList = [...]string {
|
var urlBlackList = [...]string {
|
||||||
"",
|
"",
|
||||||
" ",
|
" ",
|
||||||
|
@ -35,6 +35,11 @@ func (w WorkerContext) step(job Job) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
job.Fails++
|
job.Fails++
|
||||||
|
|
||||||
|
if err == ErrForbidden {
|
||||||
|
// Don't attempt crawling again
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if job.Fails > config.Retries {
|
if job.Fails > config.Retries {
|
||||||
atomic.AddUint64(&totalAborted, 1)
|
atomic.AddUint64(&totalAborted, 1)
|
||||||
logrus.WithField("url", job.UriStr).
|
logrus.WithField("url", job.UriStr).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user