fix: job 日志获取前校验 offset

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

View File

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