Merge pull request #219 from xhanthow/local-job

修改JobThread捕获Error错误不更新JobLog的问题
pull/4/head
许雪里 7 years ago committed by GitHub
commit dd2de9d8f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -91,12 +91,16 @@ public class JobThread extends Thread{
@Override @Override
public void run() { public void run() {
while(!toStop){ while(!toStop){
running = false; running = false;
idleTimes++; idleTimes++;
// handle job
ReturnT<String> executeResult = null;
TriggerParam triggerParam = null;
try { try {
// to check toStop signal, we need cycle, so wo cannot use queue.take(), instand of poll(timeout) // to check toStop signal, we need cycle, so wo cannot use queue.take(), instand of poll(timeout)
TriggerParam triggerParam = triggerQueue.poll(3L, TimeUnit.SECONDS); triggerParam = triggerQueue.poll(3L, TimeUnit.SECONDS);
if (triggerParam!=null) { if (triggerParam!=null) {
running = true; running = true;
idleTimes = 0; idleTimes = 0;
@ -104,10 +108,9 @@ public class JobThread extends Thread{
// parse param // parse param
String[] handlerParams = (triggerParam.getExecutorParams()!=null && triggerParam.getExecutorParams().trim().length()>0) String[] handlerParams = (triggerParam.getExecutorParams()!=null && triggerParam.getExecutorParams().trim().length()>0)
? (String[])(Arrays.asList(triggerParam.getExecutorParams().split(",")).toArray()) : null; ? (String[])(Arrays.asList(triggerParam.getExecutorParams().split(" ")).toArray()) : null;
// handle job
ReturnT<String> executeResult = null;
try { try {
// log filename: yyyy-MM-dd/9999.log // log filename: yyyy-MM-dd/9999.log
String logFileName = XxlJobFileAppender.makeLogFileName(new Date(triggerParam.getLogDateTim()), triggerParam.getLogId()); String logFileName = XxlJobFileAppender.makeLogFileName(new Date(triggerParam.getLogDateTim()), triggerParam.getLogId());
@ -135,15 +138,6 @@ public class JobThread extends Thread{
XxlJobLogger.log("<br>----------- JobThread Exception:" + errorMsg + "<br>----------- xxl-job job execute end(error) -----------"); XxlJobLogger.log("<br>----------- JobThread Exception:" + errorMsg + "<br>----------- xxl-job job execute end(error) -----------");
} }
// callback handler info
if (!toStop) {
// commonm
TriggerCallbackThread.pushCallBack(new HandleCallbackParam(triggerParam.getLogId(), executeResult));
} else {
// is killed
ReturnT<String> stopResult = new ReturnT<String>(ReturnT.FAIL_CODE, stopReason + " [业务运行中,被强制终止]");
TriggerCallbackThread.pushCallBack(new HandleCallbackParam(triggerParam.getLogId(), stopResult));
}
} else { } else {
if (idleTimes > 30) { if (idleTimes > 30) {
XxlJobExecutor.removeJobThread(jobId, "excutor idel times over limit."); XxlJobExecutor.removeJobThread(jobId, "excutor idel times over limit.");
@ -157,7 +151,21 @@ public class JobThread extends Thread{
StringWriter stringWriter = new StringWriter(); StringWriter stringWriter = new StringWriter();
e.printStackTrace(new PrintWriter(stringWriter)); e.printStackTrace(new PrintWriter(stringWriter));
String errorMsg = stringWriter.toString(); String errorMsg = stringWriter.toString();
executeResult = new ReturnT<String>(ReturnT.FAIL_CODE, errorMsg);
XxlJobLogger.log("----------- xxl-job JobThread Exception:" + errorMsg); XxlJobLogger.log("----------- xxl-job JobThread Exception:" + errorMsg);
} finally {
if(triggerParam != null) {
// callback handler info
if (!toStop) {
// commonm
TriggerCallbackThread.pushCallBack(new HandleCallbackParam(triggerParam.getLogId(), executeResult));
} else {
// is killed
ReturnT<String> stopResult = new ReturnT<String>(ReturnT.FAIL_CODE, stopReason + " [业务运行中,被强制终止]");
TriggerCallbackThread.pushCallBack(new HandleCallbackParam(triggerParam.getLogId(), stopResult));
}
}
} }
} }
@ -171,6 +179,6 @@ public class JobThread extends Thread{
} }
} }
logger.info(">>>>>>>>>>> xxl-job JobThread stoped, hashCode:{}", Thread.currentThread()); logger.info(">>>>>>>>>>>> xxl-job JobThread stoped, hashCode:{}", Thread.currentThread());
} }
} }

Loading…
Cancel
Save