MCPcopy Index your code
hub / github.com/cortexlabs/cortex / GetTaskJob

Function GetTaskJob

pkg/operator/endpoints/get_task_job.go:32–90  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

30)
31
32func GetTaskJob(w http.ResponseWriter, r *http.Request) {
33 vars := mux.Vars(r)
34 apiName := vars["apiName"]
35 jobID, err := getRequiredQueryParam("jobID", r)
36 if err != nil {
37 respondError(w, r, err)
38 return
39 }
40
41 deployedResource, err := resources.GetDeployedResourceByName(apiName)
42 if err != nil {
43 respondError(w, r, err)
44 return
45 }
46 if deployedResource.Kind != userconfig.TaskAPIKind {
47 respondError(w, r, resources.ErrorOperationIsOnlySupportedForKind(*deployedResource, userconfig.TaskAPIKind))
48 return
49 }
50
51 jobKey := spec.JobKey{
52 APIName: apiName,
53 ID: jobID,
54 Kind: userconfig.TaskAPIKind,
55 }
56
57 jobStatus, err := taskapi.GetJobStatus(jobKey)
58 if err != nil {
59 respondError(w, r, err)
60 return
61 }
62
63 apiSpec, err := operator.DownloadAPISpec(jobStatus.APIName, jobStatus.APIID)
64 if err != nil {
65 respondError(w, r, err)
66 return
67 }
68
69 endpoint, err := operator.APIEndpoint(apiSpec)
70 if err != nil {
71 respondError(w, r, err)
72 return
73 }
74
75 parsedURL, err := url.Parse(endpoint)
76 if err != nil {
77 respondError(w, r, err)
78 }
79 q := parsedURL.Query()
80 q.Add("jobID", jobKey.ID)
81 parsedURL.RawQuery = q.Encode()
82
83 response := schema.TaskJobResponse{
84 JobStatus: *jobStatus,
85 APISpec: *apiSpec,
86 Endpoint: parsedURL.String(),
87 }
88
89 respondJSON(w, r, response)

Callers

nothing calls this directly

Calls 10

GetJobStatusFunction · 0.92
DownloadAPISpecFunction · 0.92
APIEndpointFunction · 0.92
getRequiredQueryParamFunction · 0.85
respondErrorFunction · 0.85
respondJSONFunction · 0.70
AddMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected