Add retry on IP failures
This commit is contained in:
parent
ad27425471
commit
b1e10e7b09
2 changed files with 79 additions and 65 deletions
2
Makefile
2
Makefile
|
@ -13,7 +13,7 @@ LDFLAGS = -ldflags "-X ${IMPORT_PATH}/meta.Version=${VERSION} -X ${IMPORT_PATH}/
|
||||||
|
|
||||||
|
|
||||||
build:
|
build:
|
||||||
mkdir -p ${BIN_DIR} && CGO_ENABLED=0 go build ${LDFLAGS} -asmflags -trimpath=${DIR} -o ${BIN_DIR}/${BINARY} main.go
|
mkdir -p ${BIN_DIR} && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -asmflags -trimpath=${DIR} -o ${BIN_DIR}/${BINARY} main.go
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
if [ -f ${BIN_DIR}/${BINARY} ]; then rm ${BIN_DIR}/${BINARY}; fi
|
if [ -f ${BIN_DIR}/${BINARY} ]; then rm ${BIN_DIR}/${BINARY}; fi
|
||||||
|
|
|
@ -232,6 +232,9 @@ func getClient(ip *net.TCPAddr) *http.Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
func run(use string, args []string, withStdErr, withStdOut bool, stopChan stop.Chan, v ytapi.VideoParams) ([]string, error) {
|
func run(use string, args []string, withStdErr, withStdOut bool, stopChan stop.Chan, v ytapi.VideoParams) ([]string, error) {
|
||||||
|
var maxtries = 10
|
||||||
|
var attemps int
|
||||||
|
for {
|
||||||
var sourceAddress string
|
var sourceAddress string
|
||||||
var err error
|
var err error
|
||||||
for {
|
for {
|
||||||
|
@ -290,6 +293,7 @@ func run(use string, args []string, withStdErr, withStdOut bool, stopChan stop.C
|
||||||
|
|
||||||
done := make(chan error, 1)
|
done := make(chan error, 1)
|
||||||
go func() {
|
go func() {
|
||||||
|
attemps++
|
||||||
done <- cmd.Wait()
|
done <- cmd.Wait()
|
||||||
}()
|
}()
|
||||||
select {
|
select {
|
||||||
|
@ -300,12 +304,22 @@ func run(use string, args []string, withStdErr, withStdOut bool, stopChan stop.C
|
||||||
return nil, errors.Err("canceled by stopper")
|
return nil, errors.Err("canceled by stopper")
|
||||||
case err := <-done:
|
case err := <-done:
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if strings.Contains(err.Error(), "exit status 1") {
|
||||||
|
if strings.Contains(string(errorLog), "HTTP Error 429") || strings.Contains(string(errorLog), "returned non-zero exit status 8") {
|
||||||
|
v.IPPool.SetThrottled(sourceAddress)
|
||||||
|
}
|
||||||
|
if attemps > maxtries {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
return nil, errors.Prefix("youtube-dl "+strings.Join(args, " "), err)
|
return nil, errors.Prefix("youtube-dl "+strings.Join(args, " "), err)
|
||||||
}
|
}
|
||||||
|
return strings.Split(strings.Replace(string(outLog), "\r\n", "\n", -1), "\n"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errorLog) > 0 {
|
if len(errorLog) > 0 {
|
||||||
return nil, errors.Err(string(errorLog))
|
return nil, errors.Err(string(errorLog))
|
||||||
}
|
}
|
||||||
return strings.Split(strings.Replace(string(outLog), "\r\n", "\n", -1), "\n"), nil
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue