MCPcopy
hub / github.com/cortexlabs/cortex / CreateWorkload

Method CreateWorkload

pkg/async-gateway/endpoint.go:47–86  ·  view source on GitHub ↗

CreateWorkload is a handler for the async-gateway service workload creation route

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

45
46// CreateWorkload is a handler for the async-gateway service workload creation route
47func (e *Endpoint) CreateWorkload(w http.ResponseWriter, r *http.Request) {
48 requestID := r.Header.Get("x-request-id")
49 if requestID == "" {
50 respondPlainText(w, http.StatusBadRequest, "error: missing x-request-id key in request header")
51 return
52 }
53
54 apiName := r.Header.Get(consts.CortexAPINameHeader)
55 if requestID == "" {
56 respondPlainText(w, http.StatusBadRequest, fmt.Sprintf("error: missing %s key in request header", consts.CortexAPINameHeader))
57 return
58 }
59 r.Header.Del(consts.CortexAPINameHeader)
60
61 queueURL := r.Header.Get(consts.CortexQueueURLHeader)
62 if queueURL == "" {
63 respondPlainText(w, http.StatusBadRequest, fmt.Sprintf("error: missing %s key in request header", consts.CortexQueueURLHeader))
64 return
65 }
66 r.Header.Del(consts.CortexQueueURLHeader)
67
68 body := r.Body
69 defer func() {
70 _ = r.Body.Close()
71 }()
72
73 log := e.logger.With(zap.String("id", requestID), zap.String("apiName", apiName))
74
75 id, err := e.service.CreateWorkload(requestID, apiName, queueURL, body, r.Header)
76 if err != nil {
77 respondPlainText(w, http.StatusInternalServerError, fmt.Sprintf("error: %v", err))
78 logErrorWithTelemetry(log, errors.Wrap(err, "failed to create workload"))
79 return
80 }
81
82 if err = respondJSON(w, http.StatusOK, CreateWorkloadResponse{ID: id}); err != nil {
83 logErrorWithTelemetry(log, errors.Wrap(err, "failed to encode json response"))
84 return
85 }
86}
87
88// GetWorkload is a handler for the async-gateway service workload retrieval route
89func (e *Endpoint) GetWorkload(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 6

WrapFunction · 0.92
respondPlainTextFunction · 0.85
logErrorWithTelemetryFunction · 0.85
respondJSONFunction · 0.70
CreateWorkloadMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected