连接远程服务器失败, 重试60次
parent
49e2c15473
commit
dc60aae381
|
@ -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("执行超时, 强制结束")
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue