fix: 获取日志前校验 offset
This commit is contained in:
@@ -317,7 +317,7 @@ public class APIController {
|
|||||||
throw new APIException(RCode.BAD_REQUEST);
|
throw new APIException(RCode.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
Map result = Constant.PLAYBOOK_RUN_RESULT.get(id);
|
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);
|
Constant.PLAYBOOK_RUN_RESULT.remove(id);
|
||||||
}
|
}
|
||||||
return R.ok().putData(result);
|
return R.ok().putData(result);
|
||||||
@@ -333,14 +333,17 @@ public class APIController {
|
|||||||
// log file
|
// log file
|
||||||
File logFile = T.FileUtil.file(Constant.TEMP_PATH, id, "result.log");
|
File logFile = T.FileUtil.file(Constant.TEMP_PATH, id, "result.log");
|
||||||
HashMap<Object, Object> result = T.MapUtil.newHashMap(false);
|
HashMap<Object, Object> result = T.MapUtil.newHashMap(false);
|
||||||
|
|
||||||
try (RandomAccessFile raf = new RandomAccessFile(logFile, "r")) {
|
try (RandomAccessFile raf = new RandomAccessFile(logFile, "r")) {
|
||||||
raf.seek(offset);
|
if (offset < raf.length()) {
|
||||||
byte[] bytes = new byte[(int)raf.length() - offset];
|
raf.seek(offset);
|
||||||
raf.readFully(bytes);
|
byte[] bytes = new byte[(int)raf.length() - offset];
|
||||||
String content = new String(bytes);
|
raf.readFully(bytes);
|
||||||
result.put("content", content);
|
String content = new String(bytes);
|
||||||
result.put("length", bytes.length);
|
result.put("content", content);
|
||||||
result.put("offset", offset + bytes.length);
|
result.put("length", bytes.length);
|
||||||
|
result.put("offset", offset + bytes.length);
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("getJobResultLog error", e);
|
log.error("getJobResultLog error", e);
|
||||||
throw new APIException(RCode.ERROR);
|
throw new APIException(RCode.ERROR);
|
||||||
|
|||||||
Reference in New Issue
Block a user