-
Notifications
You must be signed in to change notification settings - Fork 31
/
new.go
180 lines (166 loc) · 4.34 KB
/
new.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package events
import (
"time"
"github.com/ohsu-comp-bio/funnel/tes"
)
// NewTaskCreated creates a state change event.
func NewTaskCreated(task *tes.Task) *Event {
return &Event{
Id: task.Id,
Timestamp: time.Now().Format(time.RFC3339Nano),
Type: Type_TASK_CREATED,
Data: &Event_Task{
Task: task,
},
}
}
// NewState creates a state change event.
func NewState(taskID string, s tes.State) *Event {
return &Event{
Id: taskID,
Timestamp: time.Now().Format(time.RFC3339Nano),
Type: Type_TASK_STATE,
Data: &Event_State{
State: s,
},
}
}
// NewStartTime creates a task start time event.
func NewStartTime(taskID string, attempt uint32, t time.Time) *Event {
return &Event{
Id: taskID,
Timestamp: time.Now().Format(time.RFC3339Nano),
Type: Type_TASK_START_TIME,
Attempt: attempt,
Data: &Event_StartTime{
StartTime: t.Format(time.RFC3339Nano),
},
}
}
// NewEndTime creates a task end time event.
func NewEndTime(taskID string, attempt uint32, t time.Time) *Event {
return &Event{
Id: taskID,
Timestamp: time.Now().Format(time.RFC3339Nano),
Type: Type_TASK_END_TIME,
Attempt: attempt,
Data: &Event_EndTime{
EndTime: t.Format(time.RFC3339Nano),
},
}
}
// NewOutputs creates a task output file log event.
func NewOutputs(taskID string, attempt uint32, f []*tes.OutputFileLog) *Event {
return &Event{
Id: taskID,
Timestamp: time.Now().Format(time.RFC3339Nano),
Type: Type_TASK_OUTPUTS,
Attempt: attempt,
Data: &Event_Outputs{
Outputs: &Outputs{
Value: f,
},
},
}
}
// NewMetadata creates a task metadata log event.
func NewMetadata(taskID string, attempt uint32, m map[string]string) *Event {
return &Event{
Id: taskID,
Timestamp: time.Now().Format(time.RFC3339Nano),
Type: Type_TASK_METADATA,
Attempt: attempt,
Data: &Event_Metadata{
Metadata: &Metadata{
Value: m,
},
},
}
}
// NewExecutorStartTime creates an executor start time event
// for the executor at the given index.
func NewExecutorStartTime(taskID string, attempt uint32, index uint32, t time.Time) *Event {
return &Event{
Id: taskID,
Timestamp: time.Now().Format(time.RFC3339Nano),
Type: Type_EXECUTOR_START_TIME,
Attempt: attempt,
Index: index,
Data: &Event_StartTime{
StartTime: t.Format(time.RFC3339Nano),
},
}
}
// NewExecutorEndTime creates an executor end time event.
// for the executor at the given index.
func NewExecutorEndTime(taskID string, attempt uint32, index uint32, t time.Time) *Event {
return &Event{
Id: taskID,
Timestamp: time.Now().Format(time.RFC3339Nano),
Type: Type_EXECUTOR_END_TIME,
Attempt: attempt,
Index: index,
Data: &Event_EndTime{
EndTime: t.Format(time.RFC3339Nano),
},
}
}
// NewExitCode creates an executor exit code event
// for the executor at the given index.
func NewExitCode(taskID string, attempt uint32, index uint32, x int32) *Event {
return &Event{
Id: taskID,
Timestamp: time.Now().Format(time.RFC3339Nano),
Type: Type_EXECUTOR_EXIT_CODE,
Attempt: attempt,
Index: index,
Data: &Event_ExitCode{
ExitCode: x,
},
}
}
// NewStdout creates an executor stdout chunk event
// for the executor at the given index.
func NewStdout(taskID string, attempt uint32, index uint32, s string) *Event {
return &Event{
Id: taskID,
Timestamp: time.Now().Format(time.RFC3339Nano),
Type: Type_EXECUTOR_STDOUT,
Attempt: attempt,
Index: index,
Data: &Event_Stdout{
Stdout: s,
},
}
}
// NewStderr creates an executor stderr chunk event
// for the executor at the given index.
func NewStderr(taskID string, attempt uint32, index uint32, s string) *Event {
return &Event{
Id: taskID,
Timestamp: time.Now().Format(time.RFC3339Nano),
Type: Type_EXECUTOR_STDERR,
Attempt: attempt,
Index: index,
Data: &Event_Stderr{
Stderr: s,
},
}
}
// NewSystemLog creates an system log event.
func NewSystemLog(taskID string, attempt uint32, index uint32, lvl string, msg string, fields map[string]string) *Event {
return &Event{
Id: taskID,
Timestamp: time.Now().Format(time.RFC3339Nano),
Type: Type_SYSTEM_LOG,
Attempt: attempt,
Index: index,
Data: &Event_SystemLog{
SystemLog: &SystemLog{
Msg: msg,
Level: lvl,
Fields: fields,
},
},
}
}