Added command timeout

This commit is contained in:
Erik C. Thauvin 2024-04-04 09:45:16 -07:00
parent b1c8c49fbc
commit 8b80ca1bc0
Signed by: erik
GPG key ID: 776702A6A2DA330E
4 changed files with 19 additions and 5 deletions

View file

@ -38,6 +38,7 @@ public class ExecOperation extends AbstractOperation<ExecOperation> {
private final List<String> args_ = new ArrayList<>();
private final Set<ExecFail> fail_ = new HashSet<>();
private BaseProject project_;
private int timeout = 30;
private String workDir_;
/**
@ -98,7 +99,7 @@ public class ExecOperation extends AbstractOperation<ExecOperation> {
}
var proc = pb.start();
var err = proc.waitFor(30, TimeUnit.SECONDS);
var err = proc.waitFor(timeout, TimeUnit.SECONDS);
var stdout = readStream(proc.getInputStream());
var stderr = readStream(proc.getErrorStream());
@ -180,6 +181,17 @@ public class ExecOperation extends AbstractOperation<ExecOperation> {
return lines;
}
/**
* Configure the command timeout.
*
* @param timeout The timeout in seconds
* @return this operation instance
*/
public ExecOperation timeout(int timeout) {
this.timeout = timeout;
return this;
}
/**
* Configures the working directory.
*