@@ -15,13 +15,14 @@ import (
15
15
)
16
16
17
17
var (
18
+ // ErrExecTimeout represent a timeout error
18
19
ErrExecTimeout = errors .New ("Process execution timeout" )
19
- )
20
20
21
- // Common timeout.
22
- var (
21
+ // DefaultTimeout is the timeout used by Exec* family
22
+ // of function when timeout parameter is omitted or
23
+ // passed as -1
23
24
// NOTE: could be custom in config file for default.
24
- DEFAULT = 60 * time .Second
25
+ DefaultTimeout = 60 * time .Second
25
26
)
26
27
27
28
// Process represents a working process inherit from Gogs.
@@ -51,10 +52,13 @@ func Add(desc string, cmd *exec.Cmd) int64 {
51
52
return pid
52
53
}
53
54
54
- // Exec starts executing a command in given path, it records its process and timeout.
55
+ // ExecDir runs a command in given path and waits for its completion
56
+ // up to the given timeout (or DefaultTimeout if -1 is given).
57
+ // Returns its complete stdout and stderr
58
+ // outputs and an error, if any (including timeout)
55
59
func ExecDir (timeout time.Duration , dir , desc , cmdName string , args ... string ) (string , string , error ) {
56
60
if timeout == - 1 {
57
- timeout = DEFAULT
61
+ timeout = DefaultTimeout
58
62
}
59
63
60
64
bufOut := new (bytes.Buffer )
@@ -89,12 +93,17 @@ func ExecDir(timeout time.Duration, dir, desc, cmdName string, args ...string) (
89
93
return bufOut .String (), bufErr .String (), err
90
94
}
91
95
92
- // Exec starts executing a command, it records its process and timeout.
96
+ // ExecTimeout runs a command and waits for its completion
97
+ // up to the given timeout (or DefaultTimeout if -1 is given).
98
+ // Returns its complete stdout and stderr
99
+ // outputs and an error, if any (including timeout)
93
100
func ExecTimeout (timeout time.Duration , desc , cmdName string , args ... string ) (string , string , error ) {
94
101
return ExecDir (timeout , "" , desc , cmdName , args ... )
95
102
}
96
103
97
- // Exec starts executing a command, it records its process and has default timeout.
104
+ // Exec runs a command and waits for its completion
105
+ // up to DefaultTimeout. Returns its complete stdout and stderr
106
+ // outputs and an error, if any (including timeout)
98
107
func Exec (desc , cmdName string , args ... string ) (string , string , error ) {
99
108
return ExecDir (- 1 , "" , desc , cmdName , args ... )
100
109
}
0 commit comments