(w http.ResponseWriter, r *http.Request)
| 33 | ) |
| 34 | |
| 35 | func SubmitTaskJob(w http.ResponseWriter, r *http.Request) { |
| 36 | vars := mux.Vars(r) |
| 37 | apiName := vars["apiName"] |
| 38 | |
| 39 | deployedResource, err := resources.GetDeployedResourceByName(apiName) |
| 40 | if err != nil { |
| 41 | respondError(w, r, err) |
| 42 | return |
| 43 | } |
| 44 | if deployedResource.Kind != userconfig.TaskAPIKind { |
| 45 | respondError(w, r, resources.ErrorOperationIsOnlySupportedForKind(*deployedResource, userconfig.TaskAPIKind)) |
| 46 | return |
| 47 | } |
| 48 | |
| 49 | // max payload size, same as API Gateway |
| 50 | rw := http.MaxBytesReader(w, r.Body, 10<<20) |
| 51 | |
| 52 | bodyBytes, err := ioutil.ReadAll(rw) |
| 53 | if err != nil { |
| 54 | respondError(w, r, err) |
| 55 | return |
| 56 | } |
| 57 | |
| 58 | submission := schema.TaskJobSubmission{ |
| 59 | RuntimeTaskJobConfig: spec.RuntimeTaskJobConfig{Workers: 1}, |
| 60 | } |
| 61 | |
| 62 | err = json.Unmarshal(bodyBytes, &submission) |
| 63 | if err != nil { |
| 64 | respondError(w, r, errors.Append(err, |
| 65 | fmt.Sprintf("\n\ntask job submission schema can be found at https://docs.cortex.dev/v/%s/", |
| 66 | consts.CortexVersionMinor)), |
| 67 | ) |
| 68 | return |
| 69 | } |
| 70 | |
| 71 | jobSpec, err := taskapi.SubmitJob(apiName, &submission) |
| 72 | if err != nil { |
| 73 | respondError(w, r, err) |
| 74 | return |
| 75 | } |
| 76 | |
| 77 | respondJSON(w, r, jobSpec) |
| 78 | } |
nothing calls this directly
no test coverage detected