-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
pipeline_run.go
105 lines (90 loc) · 2.92 KB
/
pipeline_run.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package presenters
import (
"time"
"gopkg.in/guregu/null.v4"
"github.com/smartcontractkit/chainlink/core/logger"
"github.com/smartcontractkit/chainlink/core/services/pipeline"
)
// Corresponds with models.d.ts PipelineRun
type PipelineRunResource struct {
JAID
Outputs []*string `json:"outputs"`
// XXX: Here for backwards compatibility, can be removed later
// Deprecated: Errors
Errors []*string `json:"errors"`
AllErrors []*string `json:"allErrors"`
FatalErrors []*string `json:"fatalErrors"`
Inputs pipeline.JSONSerializable `json:"inputs"`
TaskRuns []PipelineTaskRunResource `json:"taskRuns"`
CreatedAt time.Time `json:"createdAt"`
FinishedAt null.Time `json:"finishedAt"`
PipelineSpec PipelineSpec `json:"pipelineSpec"`
}
// GetName implements the api2go EntityNamer interface
func (r PipelineRunResource) GetName() string {
return "pipelineRun"
}
func NewPipelineRunResource(pr pipeline.Run, lggr logger.Logger) PipelineRunResource {
lggr = lggr.Named("PipelineRunResource")
var trs []PipelineTaskRunResource
for i := range pr.PipelineTaskRuns {
trs = append(trs, NewPipelineTaskRunResource(pr.PipelineTaskRuns[i]))
}
outputs, err := pr.StringOutputs()
if err != nil {
lggr.Errorw(err.Error(), "out", pr.Outputs)
}
fatalErrors := pr.StringFatalErrors()
return PipelineRunResource{
JAID: NewJAIDInt64(pr.ID),
Outputs: outputs,
Errors: fatalErrors,
AllErrors: pr.StringAllErrors(),
FatalErrors: fatalErrors,
Inputs: pr.Inputs,
TaskRuns: trs,
CreatedAt: pr.CreatedAt,
FinishedAt: pr.FinishedAt,
PipelineSpec: NewPipelineSpec(&pr.PipelineSpec),
}
}
// Corresponds with models.d.ts PipelineTaskRun
type PipelineTaskRunResource struct {
Type pipeline.TaskType `json:"type"`
CreatedAt time.Time `json:"createdAt"`
FinishedAt null.Time `json:"finishedAt"`
Output *string `json:"output"`
Error *string `json:"error"`
DotID string `json:"dotId"`
}
// GetName implements the api2go EntityNamer interface
func (r PipelineTaskRunResource) GetName() string {
return "taskRun"
}
func NewPipelineTaskRunResource(tr pipeline.TaskRun) PipelineTaskRunResource {
var output *string
if tr.Output.Valid {
outputBytes, _ := tr.Output.MarshalJSON()
outputStr := string(outputBytes)
output = &outputStr
}
var errString *string
if tr.Error.Valid {
errString = &tr.Error.String
}
return PipelineTaskRunResource{
Type: tr.Type,
CreatedAt: tr.CreatedAt,
FinishedAt: tr.FinishedAt,
Output: output,
Error: errString,
DotID: tr.GetDotID(),
}
}
func NewPipelineRunResources(prs []pipeline.Run, lggr logger.Logger) []PipelineRunResource {
var out []PipelineRunResource
for _, pr := range prs {
out = append(out, NewPipelineRunResource(pr, lggr))
}
return out
}