连接远程服务器失败, 重试60次

pull/21/merge
ouqiang 2017-05-30 09:46:35 +08:00
parent 49e2c15473
commit dc60aae381
3 changed files with 22 additions and 3 deletions

View File

@ -12,7 +12,26 @@ import (
"github.com/ouqiang/gocron/modules/logger"
)
var (
errUnavailable = errors.New("无法连接远程服务器")
)
func Exec(ip string, port int, taskReq *pb.TaskRequest) (string, error) {
tryTimes := 60
i := 0
for i < tryTimes {
output, err := exec(ip, port, taskReq)
if err != errUnavailable {
return output, err
}
i++
time.Sleep(2 * time.Second)
}
return "", errUnavailable
}
func exec(ip string, port int, taskReq *pb.TaskRequest) (string, error) {
defer func() {
if err := recover(); err != nil {
logger.Error("panic#rpc/client.go:Exec#", err)
@ -53,7 +72,7 @@ func parseGRPCError(err error, conn *grpc.ClientConn, connClosed *bool) (string,
case codes.Unavailable:
conn.Close()
*connClosed = true
return "", errors.New("无法连接远程服务器")
return "", errUnavailable
case codes.DeadlineExceeded:
return "", errors.New("执行超时, 强制结束")
}

View File

@ -104,7 +104,7 @@ func (p *GRPCPool) newCommonPool(addr string) (error) {
}
return ErrInvalidConn
},
IdleTimeout: 5 * time.Minute,
IdleTimeout: 3 * time.Minute,
}
commonPool, err := pool.NewChannelPool(poolConfig)

View File

@ -78,8 +78,8 @@
<div class="field">
<label></label>
<select name="multi">
<option value="1"{{{if .Task}}} {{{if eq .Task.Multi 1}}}selected{{{end}}} {{{end}}}></option>
<option value="2" {{{if .Task}}} {{{if eq .Task.Multi 0}}}selected{{{end}}} {{{end}}}></option>
<option value="1"{{{if .Task}}} {{{if eq .Task.Multi 1}}}selected{{{end}}} {{{end}}}></option>
</select>
</div>
</div>