package taskrpc
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"log"
|
|
)
|
|
|
|
// 完成单次任务
|
|
func DoTask(dbname, siteid, userId, task_type string, url ...string) (bool, error) {
|
|
|
|
if dbname == "" || userId == "" || task_type == ""{
|
|
return false, errors.New("参数错误")
|
|
}
|
|
|
|
conn, err := rpc_server_conn(url...)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
defer conn.Close()
|
|
|
|
data := DoTaskParam{}
|
|
data.Dbname = dbname
|
|
data.SiteId = siteid
|
|
data.UserId = userId
|
|
data.Type = task_type
|
|
|
|
req, err := SetReqData(data)
|
|
if err != nil {
|
|
log.Println("DoTask crypter error:", err)
|
|
return false, err
|
|
}
|
|
|
|
res := &Response{}
|
|
|
|
err = conn.DoTask(req, res)
|
|
|
|
if err != nil {
|
|
log.Println("taskrpc DoTask error:", err)
|
|
return false, err
|
|
}
|
|
|
|
res_data_de, err := GetResData(res)
|
|
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
if res_data_de == "" {
|
|
return false, nil
|
|
}
|
|
|
|
var task_res bool
|
|
err = json.Unmarshal([]byte(res_data_de), &task_res)
|
|
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return task_res, nil
|
|
}
|