45 lines
1.2 KiB
Go

package managed_job
import (
"flink-kube-operator/internal/crd/v1alpha1"
"strings"
"gitea.com/logicamp/lc"
"go.uber.org/zap"
)
func (job *ManagedJob) checkStatus() error {
if job.def.Status.JobId == nil {
lc.Logger.Debug("[managed-job] [status] no job id")
return v1alpha1.ErrNoJobId
}
statusResp, err := job.client.Job(*job.def.Status.JobId)
if err != nil {
lc.Logger.Debug("[managed-job] [status] cannot fetch status", zap.Error(err))
if strings.IndexAny(err.Error(), "http status not 2xx: 404") == 0 {
// job.updateState(jobState{
// JobId: job.state.JobId,
// Status: v1alpha1.JobStatusNotFound,
// })
job.crd.Patch(job.def.UID, map[string]interface{}{
"status": map[string]interface{}{
"jobId": &job.def.Status.JobId,
"jobStatus": "",
"lifeCycleStatus": v1alpha1.LifeCycleStatusFailed,
"error": "Job not found",
},
})
}
return err
}
job.crd.Patch(job.def.UID, map[string]interface{}{
"status": map[string]interface{}{
"jobId": &job.def.Status.JobId,
"jobStatus": statusResp.State,
"lifeCycleStatus": v1alpha1.LifeCycleStatusFailed,
"error": "Job not found",
},
})
return err
}