ForkingTaskRunner: Slight tweaks to setup and teardown

This commit is contained in:
Gian Merlino 2013-04-12 14:06:40 -07:00
parent a24274029f
commit c21d7f6ee2
1 changed files with 13 additions and 16 deletions

View File

@ -142,14 +142,9 @@ public class ForkingTaskRunner implements TaskRunner, TaskLogProvider
final int childPort = findUnusedPort();
final String childHost = String.format(config.getHostPattern(), childPort);
Iterables.addAll(
command,
ImmutableList.of(
config.getJavaCommand(),
"-cp",
config.getJavaClasspath()
)
);
command.add(config.getJavaCommand());
command.add("-cp");
command.add(config.getJavaClasspath());
Iterables.addAll(
command,
@ -195,24 +190,26 @@ public class ForkingTaskRunner implements TaskRunner, TaskLogProvider
final InputStream fromProc = processHolder.process.getInputStream();
final OutputStream toLogfile = Files.newOutputStreamSupplier(logFile).getOutput();
boolean copyFailed = false;
boolean runFailed = false;
try {
ByteStreams.copy(fromProc, toLogfile);
final int statusCode = processHolder.process.waitFor();
log.info("Process exited with status[%d] for task: %s", statusCode, task.getId());
if (statusCode != 0) {
runFailed = true;
}
}
catch (Exception e) {
log.warn(e, "Failed to read from process for task: %s", task.getId());
copyFailed = true;
runFailed = true;
}
finally {
Closeables.closeQuietly(fromProc);
Closeables.closeQuietly(toLogfile);
}
final int statusCode = processHolder.process.waitFor();
log.info("Process exited with status[%d] for task: %s", statusCode, task.getId());
Closeables.closeQuietly(toProc);
}
// Upload task logs
@ -222,7 +219,7 @@ public class ForkingTaskRunner implements TaskRunner, TaskLogProvider
taskLogPusher.pushTaskLog(task.getId(), logFile);
if (!copyFailed && statusCode == 0) {
if (!runFailed) {
// Process exited successfully
return jsonMapper.readValue(statusFile, TaskStatus.class);
} else {