Skip to content

Commit

Permalink
Merge pull request #23 from metrumresearchgroup/develop
Browse files Browse the repository at this point in the history
feature/error evaluation of jobs
  • Loading branch information
shairozan authored Mar 27, 2020
2 parents 35c8b62 + 4a76f6d commit 0d06124
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 0 deletions.
28 changes: 28 additions & 0 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,34 @@ func IsJobRunning(job Job) int {
return 0
}

func IsJobInErrorState(job Job) int {
knownBadStates := []string{
"auo",
"dt",
}

knownBadStateComponents := []string{
"E",
"e",
}

//Look for discrete matches first
for _, v := range knownBadStates {
if job.State == v {
return 1
}
}

//Look for state code components (eE) or others that may indicate error
for _, v := range knownBadStateComponents {
if strings.Contains(job.State,v){
return 1
}
}

return 0
}

//GetJobs returns a slice of only jobs from both scheduled and unscheduled queues
func GetJobs() (JobList, error) {
var jobs []Job
Expand Down
109 changes: 109 additions & 0 deletions job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,3 +633,112 @@ func TestTaskGroupExtrapolation(t *testing.T) {
assert.Error(t, err)

}

func TestIsJobInErrorState(t *testing.T) {
type args struct {
job Job
}
tests := []struct {
name string
args args
want int
}{
{
name: "Not errored",
args: args{
job: Job {
StateAttribute: "running",
State: "r",
JBJobNumber: 1,
JATPriority: 1,
JobName: "test",
JobOwner: "test",
StartTime: "",
SubmittedTime: "",
Slots: 1,
Tasks: Task{},
},
},
want: 0,
},
{
name: "dt State should error",
args: args{
job: Job {
StateAttribute: "running",
State: "dt",
JBJobNumber: 1,
JATPriority: 1,
JobName: "test",
JobOwner: "test",
StartTime: "",
SubmittedTime: "",
Slots: 1,
Tasks: Task{},
},
},
want: 1,
},
{
name: "auo State should error",
args: args{
job: Job {
StateAttribute: "running",
State: "auo",
JBJobNumber: 1,
JATPriority: 1,
JobName: "test",
JobOwner: "test",
StartTime: "",
SubmittedTime: "",
Slots: 1,
Tasks: Task{},
},
},
want: 1,
},
{
name: "Host error code should return error",
args: args{
job: Job {
StateAttribute: "running",
State: "Ew",
JBJobNumber: 1,
JATPriority: 1,
JobName: "test",
JobOwner: "test",
StartTime: "",
SubmittedTime: "",
Slots: 1,
Tasks: Task{},
},
},
want: 1,
},
{
name: "any individual e code should error",
args: args{
job: Job {
StateAttribute: "running",
State: "et",
JBJobNumber: 1,
JATPriority: 1,
JobName: "test",
JobOwner: "test",
StartTime: "",
SubmittedTime: "",
Slots: 1,
Tasks: Task{},
},
},
want: 1,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsJobInErrorState(tt.args.job); got != tt.want {
t.Errorf("IsJobInErrorState() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 0d06124

Please sign in to comment.