Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ShellExecutable and ConditionReader to support configurable read timeout #87

Closed
wants to merge 6 commits into from
Next Next commit
refactor: enhance ShellExecutable.Start method to support configurabl…
…e read timeout

- Added functionality to set a longer read timeout of 5000ms when the first argument is "setLongerReadTimeout".
- Updated comments to clarify the purpose of the Start method and the new read timeout behavior.
ryan-gang committed Dec 30, 2024
commit be77b1fa9faf0b3ddcb16c040a21888577076652
9 changes: 8 additions & 1 deletion internal/shell_executable/shell_executable.go
Original file line number Diff line number Diff line change
@@ -58,6 +58,8 @@ func (b *ShellExecutable) Setenv(key, value string) {
b.env.Set(key, value)
}

// Start starts the shell executable and returns an error if it fails
// If args[0] is "setLongerReadTimeout", the read timeout will be set to 5000ms
func (b *ShellExecutable) Start(args ...string) error {
b.stageLogger.Infof(b.getInitialLogLine(args...))

@@ -75,7 +77,12 @@ func (b *ShellExecutable) Start(args ...string) error {
b.cmd = cmd
b.pty = pty
b.vt = virtual_terminal.NewStandardVT()
b.ptyReader = condition_reader.NewConditionReader(io.TeeReader(b.pty, b.vt))

readTimeout := 2000 * time.Millisecond
if len(args) > 0 && args[0] == "setLongerReadTimeout" {
readTimeout = 5000 * time.Millisecond
}
b.ptyReader = condition_reader.NewConditionReader(io.TeeReader(b.pty, b.vt), readTimeout)

return nil
}