任务rpc
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.1 KiB

  1. package taskrpc
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "log"
  6. )
  7. // 完成单次任务
  8. func DoTask(dbname, siteid, userId, task_type string, url ...string) (bool, error) {
  9. if dbname == "" || userId == "" || task_type == ""{
  10. return false, errors.New("参数错误")
  11. }
  12. conn, err := rpc_server_conn(url...)
  13. if err != nil {
  14. return false, err
  15. }
  16. defer conn.Close()
  17. data := DoTaskParam{}
  18. data.Dbname = dbname
  19. data.SiteId = siteid
  20. data.UserId = userId
  21. data.Type = task_type
  22. req, err := SetReqData(data)
  23. if err != nil {
  24. log.Println("DoTask crypter error:", err)
  25. return false, err
  26. }
  27. res := &Response{}
  28. err = conn.DoTask(req, res)
  29. if err != nil {
  30. log.Println("taskrpc DoTask error:", err)
  31. return false, err
  32. }
  33. res_data_de, err := GetResData(res)
  34. if err != nil {
  35. return false, err
  36. }
  37. if res_data_de == "" {
  38. return false, nil
  39. }
  40. var task_res bool
  41. err = json.Unmarshal([]byte(res_data_de), &task_res)
  42. if err != nil {
  43. return false, err
  44. }
  45. return task_res, nil
  46. }