forked from os-autoinst/gopenqa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.go
85 lines (75 loc) · 2.2 KB
/
job.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package gopenqa
import "fmt"
/* Job instance */
type Job struct {
AssignedWorkerID int `json:"assigned_worker_id"`
BlockedByID int `json:"blocked_by_id"`
Children Children `json:"children"`
Parents Children `json:"parents"`
CloneID int64 `json:"clone_id"`
GroupID int `json:"group_id"`
ID int64 `json:"id"`
// Modules
Name string `json:"name"`
// Parents
Priority int `json:"priority"`
Result string `json:"result"`
Settings Settings `json:"settings"`
State string `json:"state"`
Tfinished string `json:"t_finished"`
Tstarted string `json:"t_started"`
Test string `json:"test"`
/* this is added by the program and not part of the fetched json */
Link string
Prefix string
Remote string // openQA remote host
instance *Instance
}
/* Children struct is for chained, directly chained and parallel children/parents */
type Children struct {
Chained []int64 `json:"Chained"`
DirectlyChained []int64 `json:"Directly chained"`
Parallel []int64 `json:"Parallel"`
}
/* Job Setting struct */
type Settings struct {
Arch string `json:"ARCH"`
Backend string `json:"BACKEND"`
Machine string `json:"MACHINE"`
}
/* Special struct for getting quick job status */
type JobState struct {
BlockedBy int64 `json:"blocked_by_id"`
Result string `json:"result"`
State string `json:"state"`
}
/* Format job as a string */
func (j *Job) String() string {
return fmt.Sprintf("%d %s (%s)", j.ID, j.Name, j.Test)
}
/* JobState returns or the job state or the result, if the job is done */
func (j *Job) JobState() string {
if j.State == "done" {
return j.Result
}
return j.State
}
/* IsCloned returns true, if the job has been cloned/restarted */
func (j *Job) IsCloned() bool {
return j.CloneID != 0 && j.CloneID != j.ID
}
/* Compares two jobs according to their unique parameters (ID, GroupID, Test) */
func (j1 *Job) Equals(j2 Job) bool {
// Compare only relevant parameters
if j1.ID != j2.ID {
return false
}
if j1.GroupID != j2.GroupID {
return false
}
if j1.Test != j2.Test {
return false
}
// Consider the other parameters as volatile and thus not important
return true
}