Skip to content

Commit 823424b

Browse files
committed
fix(cli): honor probe timeout independently
1 parent 6ef3a8b commit 823424b

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎src/main/java/io/github/easy4j/codex/cli/CodexCliExecutor.java‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public CodexCliExecutor(CodexClientConfig config) {
9393
* @return a {@link CodexCliResult} describing the outcome; never {@code null}.
9494
*/
9595
public CodexCliResult execute(String... args) {
96-
return runProcess(null, args);
96+
return runProcess(null, config.getLocalTimeoutSeconds() * 1000L, args);
9797
}
9898

9999
/**
@@ -111,10 +111,14 @@ public CodexCliResult execute(String... args) {
111111
* @return a {@link CodexCliResult} describing the outcome; never {@code null}.
112112
*/
113113
public CodexCliResult executeWithStdin(String stdin, String... args) {
114-
return runProcess(stdin, args);
114+
return runProcess(stdin, config.getLocalTimeoutSeconds() * 1000L, args);
115115
}
116116

117-
private CodexCliResult runProcess(String stdin, String... args) {
117+
private CodexCliResult executeWithTimeoutSeconds(int timeoutSeconds, String... args) {
118+
return runProcess(null, timeoutSeconds * 1000L, args);
119+
}
120+
121+
private CodexCliResult runProcess(String stdin, long timeoutMs, String... args) {
118122
CommandLine cmd = CommandLine.parse(config.getLocalExecutable());
119123
for (String arg : args) {
120124
if (arg != null) {
@@ -136,7 +140,6 @@ private CodexCliResult runProcess(String stdin, String... args) {
136140
executor.setStreamHandler(new org.apache.commons.exec.PumpStreamHandler(stdout, stderr,
137141
new ByteArrayInputStream(stdinBytes)));
138142

139-
long timeoutMs = config.getLocalTimeoutSeconds() * 1000L;
140143
ExecuteWatchdog watchdog = new ExecuteWatchdog(timeoutMs);
141144
executor.setWatchdog(watchdog);
142145

@@ -201,7 +204,7 @@ private static String utf8(ByteArrayOutputStream buffer) {
201204
*/
202205
public boolean probe() {
203206
try {
204-
CodexCliResult result = execute("--version");
207+
CodexCliResult result = executeWithTimeoutSeconds(config.getLocalProbeTimeoutSeconds(), "--version");
205208
return result.isSuccess();
206209
} catch (Exception e) {
207210
return false;

0 commit comments

Comments
 (0)