2017-05-25 14:32:40 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
pb "github.com/ouqiang/gocron/modules/rpc/proto"
|
|
|
|
"golang.org/x/net/context"
|
2017-05-26 10:09:07 +00:00
|
|
|
"fmt"
|
2017-05-25 14:32:40 +00:00
|
|
|
)
|
|
|
|
|
2017-05-26 10:09:07 +00:00
|
|
|
func Exec(ip string, port int, taskReq *pb.TaskRequest) (output string, err error) {
|
|
|
|
addr := fmt.Sprintf("%s:%d", ip, port);
|
|
|
|
conn, err := grpc.Dial(addr, grpc.WithInsecure())
|
2017-05-25 14:32:40 +00:00
|
|
|
if err != nil {
|
2017-05-26 10:09:07 +00:00
|
|
|
return
|
2017-05-25 14:32:40 +00:00
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
c := pb.NewTaskClient(conn)
|
2017-05-26 10:09:07 +00:00
|
|
|
resp, err := c.Run(context.Background(), taskReq)
|
2017-05-25 14:32:40 +00:00
|
|
|
if err != nil {
|
2017-05-26 10:09:07 +00:00
|
|
|
return
|
2017-05-25 14:32:40 +00:00
|
|
|
}
|
2017-05-26 10:09:07 +00:00
|
|
|
output = resp.Output
|
|
|
|
|
|
|
|
return
|
2017-05-25 14:32:40 +00:00
|
|
|
}
|