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

Function getTaskJob

cli/cmd/lib_task_apis.go:140–238  ·  view source on GitHub ↗
(env cliconfig.Environment, apiName string, jobID string)

Source from the content-addressed store, hash-verified

138}
139
140func getTaskJob(env cliconfig.Environment, apiName string, jobID string) (string, error) {
141 resp, err := cluster.GetTaskJob(MustGetOperatorConfig(env.Name), apiName, jobID)
142 if err != nil {
143 return "", err
144 }
145
146 var bytes []byte
147 if _flagOutput == flags.JSONOutputType {
148 bytes, err = libjson.Marshal(resp)
149 } else if _flagOutput == flags.YAMLOutputType {
150 bytes, err = yaml.Marshal(resp)
151 }
152 if err != nil {
153 return "", err
154 }
155 if _flagOutput == flags.JSONOutputType || _flagOutput == flags.YAMLOutputType {
156 return string(bytes), nil
157 }
158
159 job := resp.JobStatus
160
161 out := ""
162
163 jobIntroTable := table.KeyValuePairs{}
164 jobIntroTable.Add("job id", job.ID)
165 jobIntroTable.Add("status", job.Status.Message())
166 out += jobIntroTable.String(&table.KeyValuePairOpts{BoldKeys: pointer.Bool(true)})
167
168 jobTimingTable := table.KeyValuePairs{}
169 jobTimingTable.Add("start time", job.StartTime.Format(_timeFormat))
170
171 jobEndTime := time.Now()
172 if job.EndTime != nil {
173 jobTimingTable.Add("end time", job.EndTime.Format(_timeFormat))
174 jobEndTime = *job.EndTime
175 } else {
176 jobTimingTable.Add("end time", "-")
177 }
178 duration := jobEndTime.Sub(job.StartTime).Truncate(time.Second).String()
179 jobTimingTable.Add("duration", duration)
180
181 out += "\n" + jobTimingTable.String(&table.KeyValuePairOpts{BoldKeys: pointer.Bool(true)})
182
183 if job.Status.IsCompleted() {
184 out += "\n" + "worker stats are not available because this job is not currently running\n"
185 } else {
186 out += titleStr("worker stats")
187 if job.WorkerCounts != nil {
188 t := table.Table{
189 Headers: []table.Header{
190 {Title: "Requested"},
191 {Title: "Pending"},
192 {Title: "Creating"},
193 {Title: "Ready"},
194 {Title: "NotReady"},
195 {Title: "ErrImagePull", Hidden: job.WorkerCounts.ErrImagePull == 0},
196 {Title: "Terminating", Hidden: job.WorkerCounts.Terminating == 0},
197 {Title: "Failed", Hidden: job.WorkerCounts.Failed == 0},

Callers 1

get.goFile · 0.85

Calls 13

AddMethod · 0.95
StringMethod · 0.95
MustFormatMethod · 0.95
GetTaskJobFunction · 0.92
BoolFunction · 0.92
BoldFunction · 0.92
MustGetOperatorConfigFunction · 0.85
titleStrFunction · 0.85
MessageMethod · 0.80
SubMethod · 0.80
IsCompletedMethod · 0.80
FormatMethod · 0.45

Tested by

no test coverage detected