GetWorkload retrieves the status and result, if available, of a given workload
(id string, apiName string)
| 93 | |
| 94 | // GetWorkload retrieves the status and result, if available, of a given workload |
| 95 | func (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: ×tamp, |
| 135 | }, nil |
| 136 | } |
| 137 | |
| 138 | func (s *service) getStatus(id string, apiName string) (async.Status, error) { |
| 139 | prefix := async.StoragePath(s.clusterUID, apiName) |
nothing calls this directly
no test coverage detected