From 371fa71b50898e7b92b8ef1ce6a2d6727b2d33ab Mon Sep 17 00:00:00 2001 From: zeaslity Date: Tue, 28 Feb 2023 17:39:10 +0800 Subject: [PATCH] =?UTF-8?q?[server][=20executor]-=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=83=A8=E5=88=86=E4=BB=A3=E7=A0=81=20-=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wdd/agent/executor/CommandExecutor.java | 3 ++- .../executor/thread/CommandExecLogCache.java | 24 +++++++------------ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/agent/src/main/java/io/wdd/agent/executor/CommandExecutor.java b/agent/src/main/java/io/wdd/agent/executor/CommandExecutor.java index 7992336..923c76b 100644 --- a/agent/src/main/java/io/wdd/agent/executor/CommandExecutor.java +++ b/agent/src/main/java/io/wdd/agent/executor/CommandExecutor.java @@ -212,7 +212,8 @@ public class CommandExecutor { // 关停任务执行的缓存日志收集 BufferedReader 否则无法终止 commandExecLogCache.StopCollectExecLog( streamKey, - process + process, + commandExecWaitTimeout ); // 执行到这里,说明整个任务流程结束(超时结束) diff --git a/agent/src/main/java/io/wdd/agent/executor/thread/CommandExecLogCache.java b/agent/src/main/java/io/wdd/agent/executor/thread/CommandExecLogCache.java index 7764542..0606658 100644 --- a/agent/src/main/java/io/wdd/agent/executor/thread/CommandExecLogCache.java +++ b/agent/src/main/java/io/wdd/agent/executor/thread/CommandExecLogCache.java @@ -163,9 +163,9 @@ public class CommandExecLogCache { // 对于即时执行完成的任务,需要在这里增加尾巴内容 addCommandExecTailInfo( - process, + 1, streamKey, - false + 0 ); log.debug( @@ -183,27 +183,19 @@ public class CommandExecLogCache { * @param process * @param streamKey */ - private void addCommandExecTailInfo(Process process, String streamKey, boolean isKillProcess) { + private void addCommandExecTailInfo(int timeOut, String streamKey, int exitValue) { log.debug("开始添加任务日志的尾部信息!"); // 添加任务结束的一些信息 String execTimeCostString = String.format( "execution time-cost is => [ %s ]", - process - .info() - .totalCpuDuration() - .get() + timeOut ); - // 是否需要强行关闭 process 杀死任务进程 - /*if (isKillProcess) { - process.destroyForcibly(); - }*/ - String execResultString = String.format( "execution result code is => [ %s ]", - process.exitValue() + exitValue ); ArrayList commandExecCachedLog = CachedCommandLogMap.get(streamKey); @@ -222,7 +214,7 @@ public class CommandExecLogCache { * 对于一些没有中止的任务,必须要手动将读取的 InputStream流关闭 * 否则部分任务的日志无法收集 */ - public void StopCollectExecLog(String streamKey, Process process) { + public void StopCollectExecLog(String streamKey, Process process, int commandExecWaitTimeout) { BufferedReader bufferedReader = CommandLogBufferedReaderMap.get(streamKey); @@ -254,9 +246,9 @@ public class CommandExecLogCache { if (ObjectUtils.isNotEmpty(process) && process.isAlive()) { addCommandExecTailInfo( - process, + commandExecWaitTimeout, streamKey, - true + process.exitValue() ); }