Skip to content

Commit 0581210

Browse files
authored
Merge pull request #176 from strk/manager-lint
Lint and document manager api
2 parents 6ed7f26 + ad3d6b7 commit 0581210

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

modules/process/manager.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ import (
1515
)
1616

1717
var (
18+
// ErrExecTimeout represent a timeout error
1819
ErrExecTimeout = errors.New("Process execution timeout")
19-
)
2020

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
2324
// NOTE: could be custom in config file for default.
24-
DEFAULT = 60 * time.Second
25+
DefaultTimeout = 60 * time.Second
2526
)
2627

2728
// Process represents a working process inherit from Gogs.
@@ -51,10 +52,13 @@ func Add(desc string, cmd *exec.Cmd) int64 {
5152
return pid
5253
}
5354

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)
5559
func ExecDir(timeout time.Duration, dir, desc, cmdName string, args ...string) (string, string, error) {
5660
if timeout == -1 {
57-
timeout = DEFAULT
61+
timeout = DefaultTimeout
5862
}
5963

6064
bufOut := new(bytes.Buffer)
@@ -89,12 +93,17 @@ func ExecDir(timeout time.Duration, dir, desc, cmdName string, args ...string) (
8993
return bufOut.String(), bufErr.String(), err
9094
}
9195

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)
93100
func ExecTimeout(timeout time.Duration, desc, cmdName string, args ...string) (string, string, error) {
94101
return ExecDir(timeout, "", desc, cmdName, args...)
95102
}
96103

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)
98107
func Exec(desc, cmdName string, args ...string) (string, string, error) {
99108
return ExecDir(-1, "", desc, cmdName, args...)
100109
}

0 commit comments

Comments
 (0)