forked from MediaMath/grim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute_result.go
63 lines (51 loc) · 1.36 KB
/
execute_result.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
package grim
// Copyright 2015 MediaMath <http://www.mediamath.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"time"
)
type executeResult struct {
StartTime time.Time
EndTime time.Time
SysTime time.Duration
UserTime time.Duration
InitialEnv []string
ExitCode int
Output string `json:"-"`
}
func appendResult(resultPath string, result executeResult) error {
resultErr := writeResult(resultPath, &result)
if resultErr != nil {
return resultErr
}
return nil
}
func buildStatusFile(path string) (*os.File, error) {
filename := filepath.Join(path, "build.txt")
return os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, defaultFileMode)
}
func writeOutput(path string, outputChan chan string) {
filename := filepath.Join(path, "output.txt")
file, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, defaultFileMode)
if err != nil {
return
}
for line := range outputChan {
file.WriteString(line + "\n")
}
file.Close()
}
func writeResult(path string, result *executeResult) error {
filename := filepath.Join(path, "result.json")
if bs, err := json.Marshal(result); err != nil {
return err
} else if err := ioutil.WriteFile(filename, bs, defaultFileMode); err != nil {
return err
}
return nil
}