Commit abb490bc by huangfusuper

执行机结果发送回调重试

parent 86a64ec8
...@@ -15,6 +15,7 @@ import com.byit.node.impl.RunScriptProcessingMachine; ...@@ -15,6 +15,7 @@ import com.byit.node.impl.RunScriptProcessingMachine;
import com.byit.pool.RunThreadPool; import com.byit.pool.RunThreadPool;
import com.byit.rpc.remoting.provider.annotation.RpcService; import com.byit.rpc.remoting.provider.annotation.RpcService;
import com.byit.utils.ExecutorLogUtil; import com.byit.utils.ExecutorLogUtil;
import com.byit.utils.RequestUtil;
import com.byit.utils.ServiceInfoUtil; import com.byit.utils.ServiceInfoUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -106,7 +107,12 @@ public class ImperativeExecutionImpl implements ScriptExecutorService { ...@@ -106,7 +107,12 @@ public class ImperativeExecutionImpl implements ScriptExecutorService {
jobRunResultDto.setLogId(scriptDto.getLogId()); jobRunResultDto.setLogId(scriptDto.getLogId());
//设置远程日志文件的路径 //设置远程日志文件的路径
jobRunResultDto.setLogRemotelyPath(scriptDto.getLogRemotePath()); jobRunResultDto.setLogRemotelyPath(scriptDto.getLogRemotePath());
cn.hutool.http.HttpUtil.post(scriptDto.getCallbackUrl(), JSON.toJSONString(jobRunResultDto)); try {
RequestUtil.retryPost(scriptDto.getCallbackUrl(), JSON.toJSONString(jobRunResultDto), 3 , 1);
} catch (InterruptedException e) {
e.printStackTrace();
log.error("执行机异常:{}",ExecutorLogUtil.getMessage(e));
}
log.info("--------------runPythonScript,脚本调用结束-----------"); log.info("--------------runPythonScript,脚本调用结束-----------");
} }
} }
package com.byit.utils;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
/**
* 发送链接的工具类
* @author huangfu
*/
@Slf4j
public class RequestUtil {
/**
* 默认的超时时间
*/
final static Integer TIMEOUT_DEFAULT = 30000;
/**
* 带有重试的post请求
* @param requestUrl 请求的url
* @param body 请求的数据结果
* @param retryTotalCount 请求的总次数
* @param thisRetryCount 当前是第几次请求
* @throws InterruptedException 睡眠异常
*/
public static void retryPost(String requestUrl,String body,int retryTotalCount, int thisRetryCount) throws InterruptedException {
try {
log.info("------当前的请求的地址为:{}-------",requestUrl);
HttpUtil.post(requestUrl, body, TIMEOUT_DEFAULT);
}catch (Exception e) {
//当前重试次数 小于等于总共的重试次数时
if(thisRetryCount <= retryTotalCount){
log.error("{},出现异常,异常信息为:{},开始第{}次重试!",body,ExecutorLogUtil.getMessage(e), thisRetryCount);
Thread.sleep(1000 * thisRetryCount);
retryPost(requestUrl,body,retryTotalCount,++thisRetryCount);
}else{
throw new RuntimeException(String.format("执行机回调调度中心失败,失败原因是:%s,重试了%s次", ExecutorLogUtil.getMessage(e),retryTotalCount));
}
}
}
}
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