Commit fac8a599 by huangfusuper

失败重试日志追加

parent af4456b5
......@@ -78,6 +78,10 @@ public class ScriptExecutorJobTask implements TimerTask {
*/
private void runJob(JobTaskSchedule mythJobTaskSchedule) {
RunScriptService runScriptService = SpringUtil.getBean(RunScriptService.class);
JobTaskRunLogServiceImpl jobTaskRunLogService = SpringUtil.getBean(JobTaskRunLogServiceImpl.class);
JobTaskRunLogWithBLOBs jobTaskRunLogById = jobTaskRunLogService.findJobTaskRunLogById(mythJobTaskSchedule.getLogId());
ScriptDto scriptDto = new ScriptDto();
scriptDto.setLogId(mythJobTaskSchedule.getLogId());
scriptDto.setCommand(mythJobTaskSchedule.getRunCommand());
......@@ -85,6 +89,8 @@ public class ScriptExecutorJobTask implements TimerTask {
scriptDto.setRunId(mythJobTaskSchedule.getRunId());
scriptDto.setRemotePath(mythJobTaskSchedule.getScriptUrls());
scriptDto.setCallbackUrl("http://127.0.0.1:8998/job/callbackRes");
//二次执行的情况下 会有这个信息
scriptDto.setLogRemotePath(jobTaskRunLogById.getLogRemotelyPath());
DispatchResponseDto dispatchResponseDto = new DispatchResponseDto();
try{
dispatchResponseDto = runScriptService.runScript(scriptDto);
......
......@@ -34,4 +34,8 @@ public class ScriptDto implements Serializable {
* 回调URL
*/
private String callbackUrl;
/**
* 已有的日志路径,不存在就为null
*/
private String logRemotePath;
}
......@@ -14,6 +14,7 @@ import com.byit.pool.RunThreadPool;
import com.byit.rpc.remoting.provider.annotation.RpcService;
import com.byit.utils.ServiceInfoUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.csource.common.MyException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
......@@ -66,15 +67,27 @@ public class ScriptExecutorServiceImpl implements ScriptExecutorService {
//开始执行脚本
List<String> cmdList = Arrays.asList(command,scriptPath);
MythJobProcess mythJobProcess = new MythJobProcess(cmdList, null, null, scriptDto.getLogId());
//保存日志
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 {
//上传日志文件
logPath = fileSystem.uploadFile(logDataByte,"log",fileMateData);
jobRunResultDto.setReturnResult(ReturnResult.SUCCESS);
//不为空 则追加
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) {
......@@ -106,6 +119,20 @@ public class ScriptExecutorServiceImpl implements ScriptExecutorService {
return dispatchResponseDto;
}
/**
* 合并两个字节数组
* @param sourceByte
* @param targetByte
* @return
*/
private byte[] mergeFile(byte[] sourceByte, byte[] targetByte){
byte[] result = new byte[sourceByte.length+targetByte.length];
System.arraycopy(sourceByte,0,result,0,sourceByte.length);
System.arraycopy(targetByte,0,result,sourceByte.length,targetByte.length);
return result;
}
/**
* 将脚本字节转换成文件
* @return 生成文件的本地路径
......
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