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

jobset.go 2.0 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package scheduler
  2. import (
  3. "fmt"
  4. "net/url"
  5. "strings"
  6. "gitlink.org.cn/cloudream/common/consts/errorcode"
  7. "gitlink.org.cn/cloudream/common/models"
  8. myhttp "gitlink.org.cn/cloudream/common/utils/http"
  9. "gitlink.org.cn/cloudream/common/utils/serder"
  10. )
  11. type JobSetSumbitReq struct {
  12. models.JobSetInfo
  13. }
  14. type JobSetSumbitResp struct {
  15. JobSetID string `json:"jobSetID"`
  16. }
  17. func (c *Client) JobSetSumbit(req JobSetSumbitReq) (*JobSetSumbitResp, error) {
  18. url, err := url.JoinPath(c.baseURL, "/jobSet/submit")
  19. if err != nil {
  20. return nil, err
  21. }
  22. resp, err := myhttp.PostJSON(url, myhttp.RequestParam{
  23. Body: req,
  24. })
  25. if err != nil {
  26. return nil, err
  27. }
  28. contType := resp.Header.Get("Content-Type")
  29. if strings.Contains(contType, myhttp.ContentTypeJSON) {
  30. var codeResp response[JobSetSumbitResp]
  31. if err := serder.JSONToObjectStream(resp.Body, &codeResp); err != nil {
  32. return nil, fmt.Errorf("parsing response: %w", err)
  33. }
  34. if codeResp.Code == errorcode.OK {
  35. return &codeResp.Data, nil
  36. }
  37. return nil, codeResp.ToError()
  38. }
  39. return nil, fmt.Errorf("unknow response content type: %s", contType)
  40. }
  41. type JobSetSetLocalFileReq struct {
  42. JobSetID string `json:"jobSetID"`
  43. LocalPath string `json:"localPath"`
  44. PackageID int64 `json:"packageID"`
  45. }
  46. func (c *Client) JobSetSetLocalFile(req JobSetSetLocalFileReq) error {
  47. url, err := url.JoinPath(c.baseURL, "/jobSet/setLocalFile")
  48. if err != nil {
  49. return err
  50. }
  51. resp, err := myhttp.PostJSON(url, myhttp.RequestParam{
  52. Body: req,
  53. })
  54. if err != nil {
  55. return err
  56. }
  57. contType := resp.Header.Get("Content-Type")
  58. if strings.Contains(contType, myhttp.ContentTypeJSON) {
  59. var codeResp response[any]
  60. if err := serder.JSONToObjectStream(resp.Body, &codeResp); err != nil {
  61. return fmt.Errorf("parsing response: %w", err)
  62. }
  63. if codeResp.Code == errorcode.OK {
  64. return nil
  65. }
  66. return codeResp.ToError()
  67. }
  68. return fmt.Errorf("unknow response content type: %s", contType)
  69. }