-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_section.go
49 lines (38 loc) · 875 Bytes
/
build_section.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
package helpers
import (
"fmt"
"time"
)
type RawLogger interface {
SendRawLog(args ...interface{})
}
type BuildSection struct {
Name string
SkipMetrics bool
Run func() error
}
const (
traceSectionStart = "section_start:%v:%s\r" + ANSI_CLEAR
traceSectionEnd = "section_end:%v:%s\r" + ANSI_CLEAR
)
func nowUnixUTC() int64 {
return time.Now().UTC().Unix()
}
func (s *BuildSection) timestamp(format string, logger RawLogger) {
if s.SkipMetrics {
return
}
sectionLine := fmt.Sprintf(format, nowUnixUTC(), s.Name)
logger.SendRawLog(sectionLine)
}
func (s *BuildSection) start(logger RawLogger) {
s.timestamp(traceSectionStart, logger)
}
func (s *BuildSection) end(logger RawLogger) {
s.timestamp(traceSectionEnd, logger)
}
func (s *BuildSection) Execute(logger RawLogger) error {
s.start(logger)
defer s.end(logger)
return s.Run()
}