Commit 4492cf56 by huangfusuper

解决立即执行异常卡死状态

parent c68f875c
......@@ -20,6 +20,7 @@ import io.netty.util.Timeout;
import io.netty.util.TimerTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.validation.annotation.Validated;
import java.util.Date;
......@@ -35,6 +36,7 @@ public class ScriptExecutorJobTask implements TimerTask {
private static final String HTTP_PRE = "http://";
private static final String HTTP_SUFFIX = "/myth-job-admin/job/callbackRes";
public static final String LINE = "\n";
private static final Integer INIT_SLEEP_TIME = 100;
private JobTaskSchedule mythJobTaskSchedule;
......@@ -90,22 +92,22 @@ public class ScriptExecutorJobTask implements TimerTask {
* @param mythJobTaskSchedule 运行的排期表
*/
private void runJob(JobTaskSchedule mythJobTaskSchedule) {
RunScriptService runScriptService = SpringUtil.getBean(RunScriptService.class);
JobTaskRunLogServiceImpl jobTaskRunLogService = SpringUtil.getBean(JobTaskRunLogServiceImpl.class);
log.info("--------------logid:{}----------",mythJobTaskSchedule.getLogId());
JobTaskRunLogWithBLOBs jobTaskRunLogById = jobTaskRunLogService.findJobTaskRunLogById(mythJobTaskSchedule.getLogId());
log.info("--------------jobTaskRunLogById:{}----------",jobTaskRunLogById);
ScriptDto scriptDto = new ScriptDto();
scriptDto.setLogId(mythJobTaskSchedule.getLogId());
scriptDto.setCommand(mythJobTaskSchedule.getRunCommand());
scriptDto.setParam(mythJobTaskSchedule.getRunParam());
scriptDto.setRunId(mythJobTaskSchedule.getRunId());
scriptDto.setRemotePath(mythJobTaskSchedule.getScriptUrls());
scriptDto.setCallbackUrl(HTTP_PRE+ ServiceInfoUtil.getIpAndPort()+HTTP_SUFFIX);
//二次执行的情况下 会有这个信息 //TODO 还是有问题
scriptDto.setLogRemotePath(jobTaskRunLogById.getLogRemotelyPath());
DispatchResponseDto dispatchResponseDto = new DispatchResponseDto();
try{
RunScriptService runScriptService = SpringUtil.getBean(RunScriptService.class);
JobTaskRunLogServiceImpl jobTaskRunLogService = SpringUtil.getBean(JobTaskRunLogServiceImpl.class);
log.info("--------------logid:{}----------",mythJobTaskSchedule.getLogId());
JobTaskRunLogWithBLOBs jobTaskRunLogById = jobTaskRunLogService.findJobTaskRunLogById(mythJobTaskSchedule.getLogId());
jobTaskRunLogById = spinLock(jobTaskRunLogById);
ScriptDto scriptDto = new ScriptDto();
scriptDto.setLogId(mythJobTaskSchedule.getLogId());
scriptDto.setCommand(mythJobTaskSchedule.getRunCommand());
scriptDto.setParam(mythJobTaskSchedule.getRunParam());
scriptDto.setRunId(mythJobTaskSchedule.getRunId());
scriptDto.setRemotePath(mythJobTaskSchedule.getScriptUrls());
scriptDto.setCallbackUrl(HTTP_PRE+ ServiceInfoUtil.getIpAndPort()+HTTP_SUFFIX);
//二次执行的情况下 会有这个信息
scriptDto.setLogRemotePath(jobTaskRunLogById.getLogRemotelyPath());
dispatchResponseDto = runScriptService.runScript(scriptDto);
}catch (Exception e){
StringRedisTemplate stringRedisTemplate = (StringRedisTemplate) SpringUtil.getBean("stringRedisTemplate");
......@@ -121,6 +123,31 @@ public class ScriptExecutorJobTask implements TimerTask {
saveLog(mythJobTaskSchedule,dispatchResponseDto);
}
/**
* 模拟自旋锁实现
* @param jobTaskRunLogById
* @return
* @throws InterruptedException
*/
private JobTaskRunLogWithBLOBs spinLock (JobTaskRunLogWithBLOBs jobTaskRunLogById) throws InterruptedException {
JobTaskRunLogServiceImpl jobTaskRunLogService = SpringUtil.getBean(JobTaskRunLogServiceImpl.class);
int i = 1;
while (jobTaskRunLogById ==null) {
Thread.sleep(i*INIT_SLEEP_TIME);
jobTaskRunLogById = jobTaskRunLogService.findJobTaskRunLogById(mythJobTaskSchedule.getLogId());
if(i >= 3){
break;
}
i++;
}
if(jobTaskRunLogById != null){
return jobTaskRunLogById;
}
throw new RuntimeException("服务器分配资源失败");
}
private void saveLog(JobTaskSchedule mythJobTaskSchedule, DispatchResponseDto dispatchResponseDto){
log.debug("-----------saveLog--保存脚本调度日志开始------------");
JobTaskRunLogServiceImpl jobTaskRunLogService = SpringUtil.getBean(JobTaskRunLogServiceImpl.class);
......
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