fix: 获取日志前校验 offset

This commit is contained in:
zhangshuai
2024-11-05 09:46:27 +08:00
parent 3965a7a44d
commit 88d4638c27

View File

@@ -317,7 +317,7 @@ public class APIController {
throw new APIException(RCode.BAD_REQUEST);
}
Map result = Constant.PLAYBOOK_RUN_RESULT.get(id);
if (!T.MapUtil.getStr(result, "status").equals("running")){
if (T.MapUtil.isNotEmpty(result) && !T.MapUtil.getStr(result, "status").equals("running")){
Constant.PLAYBOOK_RUN_RESULT.remove(id);
}
return R.ok().putData(result);
@@ -333,14 +333,17 @@ public class APIController {
// log file
File logFile = T.FileUtil.file(Constant.TEMP_PATH, id, "result.log");
HashMap<Object, Object> result = T.MapUtil.newHashMap(false);
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()) {
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("getJobResultLog error", e);
throw new APIException(RCode.ERROR);