fix: job 日志获取前校验 offset

This commit is contained in:
zhangshuai
2024-11-05 09:55:18 +08:00
parent 9ccd0ecc1f
commit 7e7ef56794

View File

@@ -156,13 +156,20 @@ public class JobServiceImpl extends ServiceImpl<JobDao, JobEntity> implements IJ
if (logFile.exists()){
try (RandomAccessFile raf = new RandomAccessFile(logFile, "r")) {
raf.seek(offset);
byte[] bytes = new byte[(int)raf.length() - offset];
raf.readFully(bytes);
String content = new String(bytes);
result.put("content", content);
result.put("length", bytes.length);
result.put("offset", offset + bytes.length);
if (offset > raf.length()){
result.put("content", T.StrUtil.EMPTY);
result.put("length", 0);
result.put("offset", offset);
}else {
raf.seek(offset);
byte[] bytes = new byte[(int)raf.length() - offset];
raf.readFully(bytes);
String content = new String(bytes);
result.put("content", content);
result.put("length", bytes.length);
result.put("offset", offset + bytes.length);
}
} catch (IOException e) {
log.error("queryJobLog error", e);
throw new ASWException(RCode.ERROR);