Skip to content

Commit 3ddad15

Browse files
authored
Merge pull request #36 from uc-cdis/fix/retries
fix(retries): retry limited times
2 parents fdf95bd + aa5ec06 commit 3ddad15

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

handlers/handler.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import (
1313
"github.com/golang/glog"
1414
)
1515

16+
const (
17+
MAX_RETRIES int = 3
18+
)
19+
1620
type SQSHandler struct {
1721
QueueURL string
1822
Start bool
@@ -145,9 +149,11 @@ func (handler *SQSHandler) StartMonitoringProcess() {
145149
if k8sJob.Status == "Unknown" || k8sJob.Status == "Running" || k8sJob.Status == "Completed" {
146150
jobInfo.Status = k8sJob.Status
147151
} else if k8sJob.Status == "Failed" {
148-
glog.Errorf("The k8s job %s failed. Detail %s", jobInfo.Name, err)
149-
//glog.Errorf("The k8s job %s failed. Detail %s. Resend the message to the queue", jobInfo.Name, err)
150-
//handler.ResendSQSMessage(handler.QueueURL, jobInfo.SQSMessage)
152+
if jobInfo.Retries < MAX_RETRIES {
153+
glog.Errorf("The k8s job %s failed. Detail %s. Resend the message to the queue", jobInfo.Name, err)
154+
handler.ResendSQSMessage(handler.QueueURL, jobInfo.SQSMessage)
155+
jobInfo.Retries += 1
156+
}
151157
}
152158
}
153159
nextMonitoredJobs = append(nextMonitoredJobs, jobInfo)

handlers/jobs.go

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type JobInfo struct {
3131
Name string `json:"name"`
3232
Status string `json:"status"`
3333
URL string `json:"url"`
34+
Retries int `json:"retries"`
3435
SQSMessage *sqs.Message
3536
}
3637

@@ -327,6 +328,7 @@ func CreateK8sJob(inputURL string, jobConfig JobConfig) (*JobInfo, error) {
327328
ji.Name = newJob.Name
328329
ji.UID = string(newJob.GetUID())
329330
ji.URL = inputURL
331+
ji.Retries = 0
330332
ji.Status = jobStatusToString(&newJob.Status)
331333
return &ji, nil
332334
}

0 commit comments

Comments
 (0)