Commit 5b9da215 by huangfusuper

解决脚本运行不通知异常的BUG

parent 7f690086
...@@ -32,7 +32,7 @@ public class WaitingRecordServiceImpl implements WaitingRecordService { ...@@ -32,7 +32,7 @@ public class WaitingRecordServiceImpl implements WaitingRecordService {
*/ */
@Override @Override
public List<WaitingRecord> findAllByTriggerTime(long triggerTime) { public List<WaitingRecord> findAllByTriggerTime(long triggerTime) {
log.info("------查询对应的等待工作流--------"); log.debug("------查询对应的等待工作流--------");
return waitingRecordMapper.findAllByTriggerTime(triggerTime); return waitingRecordMapper.findAllByTriggerTime(triggerTime);
} }
......
...@@ -29,7 +29,7 @@ import java.util.Date; ...@@ -29,7 +29,7 @@ import java.util.Date;
public class ScriptExecutorJobTask implements TimerTask { public class ScriptExecutorJobTask implements TimerTask {
private final String HTTP_PRE = "http://"; private final String HTTP_PRE = "http://";
private final String HTTP_SUFFIX = "/job/callbackRes"; private final String HTTP_SUFFIX = "/myth-job-admin/job/callbackRes";
private JobTaskSchedule mythJobTaskSchedule; private JobTaskSchedule mythJobTaskSchedule;
...@@ -101,16 +101,16 @@ public class ScriptExecutorJobTask implements TimerTask { ...@@ -101,16 +101,16 @@ public class ScriptExecutorJobTask implements TimerTask {
try{ try{
dispatchResponseDto = runScriptService.runScript(scriptDto); dispatchResponseDto = runScriptService.runScript(scriptDto);
}catch (RpcException rpcException){ }catch (RpcException rpcException){
log.error("------执行机异常{}-----",rpcException.getMessage());
dispatchResponseDto.setMsg(rpcException.getMessage()); dispatchResponseDto.setMsg(rpcException.getMessage());
dispatchResponseDto.setCode(JobResultEnum.DISPATCH_FAIL.getRes()); dispatchResponseDto.setCode(JobResultEnum.DISPATCH_FAIL.getRes());
log.error("--------------执行机不存在----------------");
} }
saveLog(mythJobTaskSchedule,dispatchResponseDto); saveLog(mythJobTaskSchedule,dispatchResponseDto);
} }
private void saveLog(JobTaskSchedule mythJobTaskSchedule, DispatchResponseDto dispatchResponseDto){ private void saveLog(JobTaskSchedule mythJobTaskSchedule, DispatchResponseDto dispatchResponseDto){
log.info("-----------saveLog--保存脚本调度日志开始------------"); log.debug("-----------saveLog--保存脚本调度日志开始------------");
JobTaskRunLogServiceImpl jobTaskRunLogService = SpringUtil.getBean(JobTaskRunLogServiceImpl.class); JobTaskRunLogServiceImpl jobTaskRunLogService = SpringUtil.getBean(JobTaskRunLogServiceImpl.class);
JobTaskRunLogWithBLOBs jobTaskRunLogById = jobTaskRunLogService.findJobTaskRunLogById(mythJobTaskSchedule.getLogId()); JobTaskRunLogWithBLOBs jobTaskRunLogById = jobTaskRunLogService.findJobTaskRunLogById(mythJobTaskSchedule.getLogId());
......
...@@ -54,73 +54,11 @@ public class ScriptExecutorServiceImpl implements ScriptExecutorService { ...@@ -54,73 +54,11 @@ public class ScriptExecutorServiceImpl implements ScriptExecutorService {
@Override @Override
public DispatchResponseDto runPythonScript(ScriptDto scriptDto) { public DispatchResponseDto runPythonScript(ScriptDto scriptDto) {
log.info("----------------runPythonScript start{} ------------------------",scriptDto);
DispatchResponseDto dispatchResponseDto; DispatchResponseDto dispatchResponseDto;
try { try {
RunThreadPool.SCRIPT_RUN_THREAD_POOL.execute(()->{ RunThreadPool.SCRIPT_RUN_THREAD_POOL.execute(()->{
log.info("--------------runPythonScript,脚本调用开始-----------"); startScript(scriptDto);
//创建回复对象
JobRunResultDto jobRunResultDto = new JobRunResultDto();
jobRunResultDto.setStartTime(new Date());
//设定运行标识
jobRunResultDto.setJobRunId(scriptDto.getRunId());
//获取回调通知URL
String callbackUrl = scriptDto.getCallbackUrl();
String remotePath = scriptDto.getRemotePath();
String command = scriptDto.getCommand();
String param = scriptDto.getParam();
ScriptParamAndPlaceholderDto scriptParamAndPlaceholderDto = null;
if(null != param){
scriptParamAndPlaceholderDto = JSON.parseObject(param, ScriptParamAndPlaceholderDto.class);
}
String scriptPath = byteArrayToFile(remotePath,scriptParamAndPlaceholderDto);
log.info("-------------脚本所在路径为:{}-------------",scriptPath);
//初始化命令信息
command = PlaceholderUtils.initCommand(command,scriptPath);
//开始执行脚本
if(scriptParamAndPlaceholderDto != null){
command = PlaceholderUtils.commandReplace(command,scriptParamAndPlaceholderDto.getParam());
}
List<String> cmdList = Arrays.asList(command.split(" "));
MythJobProcess mythJobProcess = new MythJobProcess(cmdList, null, null, scriptDto.getLogId(), scriptDto.getRunId(), stringRedisTemplate);
//保存日志
String logData = mythJobProcess.call();
byte[] logDataByte = stringToByteArray(logData);
Map<String,String> fileMateData = new HashMap<String,String>(2);
fileMateData.put("filename",scriptDto.getRunId()+scriptDto.getRunId()+".log");
String logPath = "";
try {
//不为空 则追加
if(scriptDto.getLogRemotePath() != null){
byte[] sourceLogByte = fileSystem.downloaderFile(scriptDto.getLogRemotePath());
byte[] resultLogByte = mergeFile(sourceLogByte, logDataByte);
//上传日志文件
logPath = fileSystem.uploadFile(resultLogByte,"log",fileMateData);
//删除原有的日志文件
fileSystem.fileRemove(scriptDto.getLogRemotePath());
}else{
//上传日志文件
logPath = fileSystem.uploadFile(logDataByte,"log",fileMateData);
jobRunResultDto.setReturnResult(ReturnResult.SUCCESS);
}
} catch (ProcessFailureException ignored){
jobRunResultDto.setReturnResult(ReturnResult.FAIL);
} catch (IOException | MyException e) {
jobRunResultDto.setReturnResult(ReturnResult.FAIL);
e.printStackTrace();
}
log.info("-----------执行命令,{},{}-----------",command,scriptPath);
//设置结束时间
jobRunResultDto.setEndTime(new Date());
jobRunResultDto.setLogId(scriptDto.getLogId());
//设置远程日志文件的路径
jobRunResultDto.setLogRemotelyPath(logPath);
cn.hutool.http.HttpUtil.post(callbackUrl, JSON.toJSONString(jobRunResultDto));
log.info("--------------runPythonScript,脚本调用结束-----------");
}); });
dispatchResponseDto = DispatchResponseDto.builder() dispatchResponseDto = DispatchResponseDto.builder()
...@@ -134,10 +72,77 @@ public class ScriptExecutorServiceImpl implements ScriptExecutorService { ...@@ -134,10 +72,77 @@ public class ScriptExecutorServiceImpl implements ScriptExecutorService {
.build(); .build();
} }
dispatchResponseDto.setUrl(ServiceInfoUtil.getIpAndPort()); dispatchResponseDto.setUrl(ServiceInfoUtil.getIpAndPort());
log.info("----------------runPythonScript end---------------------");
return dispatchResponseDto; return dispatchResponseDto;
} }
public void startScript(ScriptDto scriptDto){
log.info("--------------runPythonScript,脚本调用开始-----------");
//创建回复对象
JobRunResultDto jobRunResultDto = new JobRunResultDto();
jobRunResultDto.setStartTime(new Date());
//设定运行标识
jobRunResultDto.setJobRunId(scriptDto.getRunId());
//获取回调通知URL
String callbackUrl = scriptDto.getCallbackUrl();
String remotePath = scriptDto.getRemotePath();
String command = scriptDto.getCommand();
String param = scriptDto.getParam();
ScriptParamAndPlaceholderDto scriptParamAndPlaceholderDto = null;
if(null != param){
scriptParamAndPlaceholderDto = JSON.parseObject(param, ScriptParamAndPlaceholderDto.class);
}
String scriptPath = byteArrayToFile(remotePath,scriptParamAndPlaceholderDto);
log.info("-------------脚本所在路径为:{}-------------",scriptPath);
//初始化命令信息
command = PlaceholderUtils.initCommand(command,scriptPath);
//开始执行脚本
if(scriptParamAndPlaceholderDto != null){
command = PlaceholderUtils.commandReplace(command,scriptParamAndPlaceholderDto.getParam());
}
List<String> cmdList = Arrays.asList(command.split(" "));
MythJobProcess mythJobProcess = new MythJobProcess(cmdList, null, null, scriptDto.getLogId(), scriptDto.getRunId(), stringRedisTemplate);
//保存日志
String logData = mythJobProcess.call();
byte[] logDataByte = stringToByteArray(logData);
Map<String,String> fileMateData = new HashMap<String,String>(2);
fileMateData.put("filename",scriptDto.getRunId()+scriptDto.getRunId()+".log");
String logPath = "";
try {
//不为空 则追加
if(scriptDto.getLogRemotePath() != null){
byte[] sourceLogByte = fileSystem.downloaderFile(scriptDto.getLogRemotePath());
byte[] resultLogByte = mergeFile(sourceLogByte, logDataByte);
//上传日志文件
logPath = fileSystem.uploadFile(resultLogByte,"log",fileMateData);
//删除原有的日志文件
fileSystem.fileRemove(scriptDto.getLogRemotePath());
}else{
//上传日志文件
logPath = fileSystem.uploadFile(logDataByte,"log",fileMateData);
jobRunResultDto.setReturnResult(ReturnResult.SUCCESS);
}
} catch (ProcessFailureException ignored){
jobRunResultDto.setReturnResult(ReturnResult.FAIL);
} catch (IOException | MyException e) {
jobRunResultDto.setReturnResult(ReturnResult.FAIL);
e.printStackTrace();
}
log.info("-----------执行命令,{},{}-----------",command,scriptPath);
//设置结束时间
jobRunResultDto.setEndTime(new Date());
jobRunResultDto.setLogId(scriptDto.getLogId());
//设置远程日志文件的路径
jobRunResultDto.setLogRemotelyPath(logPath);
cn.hutool.http.HttpUtil.post(callbackUrl, JSON.toJSONString(jobRunResultDto));
log.info("--------------runPythonScript,脚本调用结束-----------");
}
/** /**
* 合并两个字节数组 * 合并两个字节数组
......
...@@ -14,7 +14,7 @@ import java.util.concurrent.TimeUnit; ...@@ -14,7 +14,7 @@ import java.util.concurrent.TimeUnit;
public class AddComplexPy { public class AddComplexPy {
public static void main(String[] args) { public static void main(String[] args) {
RunNode runNode = new RunNode(); RunNode runNode = new RunNode();
runNode.setScriptUrl("ddmp/M00/00/00/CgB4Al5wa36AaUJ7AAAAiYy1k-k9801.py"); runNode.setScriptUrl("ddmp/M00/00/01/CgB4Al5wa6WAfhQ9AAAAN9Xm1mU1221.py");
runNode.setJobType("PYTHON"); runNode.setJobType("PYTHON");
runNode.setNodeId("2"); runNode.setNodeId("2");
runNode.setNodeName("lijkki"); runNode.setNodeName("lijkki");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment