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

Method GetWorkload

pkg/async-gateway/service.go:95–136  ·  view source on GitHub ↗

GetWorkload retrieves the status and result, if available, of a given workload

(id string, apiName string)

Source from the content-addressed store, hash-verified

93
94// GetWorkload retrieves the status and result, if available, of a given workload
95func (s *service) GetWorkload(id string, apiName string) (GetWorkloadResponse, error) {
96 log := s.logger.With(zap.String("id", id), zap.String("apiName", apiName))
97
98 st, err := s.getStatus(id, apiName)
99 if err != nil {
100 return GetWorkloadResponse{}, err
101 }
102
103 if st != async.StatusCompleted {
104 return GetWorkloadResponse{
105 ID: id,
106 Status: st,
107 }, nil
108 }
109
110 // attempt to download user result
111 prefix := async.StoragePath(s.clusterUID, apiName)
112 resultPath := async.ResultPath(prefix, id)
113 log.Debug("downloading user result", zap.String("path", resultPath))
114 resultBuf, err := s.storage.Download(resultPath)
115 if err != nil {
116 return GetWorkloadResponse{}, err
117 }
118
119 var userResponse UserResponse
120 if err = json.Unmarshal(resultBuf, &userResponse); err != nil {
121 return GetWorkloadResponse{}, err
122 }
123
124 log.Debug("getting workload timestamp")
125 timestamp, err := s.storage.GetLastModified(resultPath)
126 if err != nil {
127 return GetWorkloadResponse{}, err
128 }
129
130 return GetWorkloadResponse{
131 ID: id,
132 Status: st,
133 Result: &userResponse,
134 Timestamp: &timestamp,
135 }, nil
136}
137
138func (s *service) getStatus(id string, apiName string) (async.Status, error) {
139 prefix := async.StoragePath(s.clusterUID, apiName)

Callers

nothing calls this directly

Calls 6

getStatusMethod · 0.95
StoragePathFunction · 0.92
ResultPathFunction · 0.92
DownloadMethod · 0.65
GetLastModifiedMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected