forked from hofstadter-io/hof
-
Notifications
You must be signed in to change notification settings - Fork 0
/
task.go
60 lines (49 loc) · 945 Bytes
/
task.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
package task
import (
"time"
"cuelang.org/go/cue"
cueflow "cuelang.org/go/tools/flow"
"github.com/google/uuid"
)
type Task interface {
IDer
Eventer
TimeEventer
}
type IDer interface {
ID() string
UUID() string
}
type Eventer interface {
EmitEvent(key string, data interface{})
}
type TimeEventer interface {
AddTimeEvent(key string)
}
type BaseTask struct {
// IDer
ID string
UUID uuid.UUID
// cue bookkeeping
CueTask *cueflow.Task
Orig cue.Value
Start cue.Value
Final cue.Value
Error error
// stats & timing
// should this be a list with names / times
// timing
// replace with open telemetry
TimeEvents map[string]time.Time
}
func NewBaseTask(val cue.Value) *BaseTask {
return &BaseTask{
ID: val.Path().String(),
UUID: uuid.New(),
Orig: val,
TimeEvents: make(map[string]time.Time),
}
}
func (T *BaseTask) AddTimeEvent(key string) {
T.TimeEvents[key] = time.Now()
}