-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjob.go
59 lines (48 loc) · 1.31 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
package models
import (
"encoding/json"
"github.com/pkg/errors"
)
type Value struct {
Value interface{} `json:"value" bson:"value"`
Target string `json:"target" bson:"target"`
}
func (v *Value) UnmarshalJSON(document []byte) error {
var partialValue struct {
Target string `json:"target"`
Value json.RawMessage `json:"value"`
}
err := json.Unmarshal(document, &partialValue)
if err != nil {
return errors.Wrapf(err, "cannot unmarshal partial value")
}
v.Target = partialValue.Target
var arr []string
err = json.Unmarshal(partialValue.Value, &arr)
if err == nil {
v.Value = arr
return nil
}
var str string
err = json.Unmarshal(partialValue.Value, &str)
if err == nil {
v.Value = str
return nil
}
return err
}
type Job struct {
Metadata `json:",inline" bson:",inline"`
// the workflow is either a workflow or a reference to one in the database
Type ComponentType `json:"type" bson:"type"`
InputValues []Value `json:"inputValues,omitempty" bson:"inputValues,omitempty"`
Workflow Workflow `json:"workflow" bson:"workflow"`
}
type JobPostRequest struct {
Job Job `json:"job"`
SubmitOptions JobPostOptions `json:"options"`
}
type JobPostOptions struct {
Constants []interface{} `json:"constants"`
Tags []string `json:"tags"`
}