super("tail", "log");
}
@Override
public Object runCommand() throws PlatformLayerClientException, InterruptedException {
PlatformLayerClient client = getPlatformLayerClient();
// TODO: System.out isn't quite right
JobLogPrinter jobLogPrinter = new JobLogPrinter(new PrintWriter(System.out));
if (Strings.isNullOrEmpty(executionId)) {
JobExecutionList jobExecutions = client.listJobExecutions(jobId);
JobExecutionData last = null;
for (JobExecutionData execution : jobExecutions.getRuns()) {
if (execution.getState() == JobState.PRESTART) {
continue;
}
if (last == null) {
last = execution;
continue;
}
if (last.getStartedAt().before(execution.getStartedAt())) {
last = execution;
continue;
}
}
if (last != null) {
executionId = last.getExecutionId();
}
}
// TODO: What if executionId == null? Also retries..
JobLog previousJobLog = null;
int jobLogOffset = 0;
while (true) {
// TODO: Only fetch tail
JobLog jobLog = client.getJobExecutionLog(jobId, executionId);
if (previousJobLog == null) {
jobLogPrinter.startJobLog(jobLog);
}
List<JobLogLine> lines = jobLog.getLines();