IJobHandler取消任务返回值,原通过返回值判断执行状态,逻辑改为:默认任务执行成功,仅在捕获异常时认定任务执行失败。

v1.4
xueli.xue 8 years ago
parent 6b0d17a4c6
commit 148b7ca5e3

@ -589,9 +589,11 @@ XXL-JOB会为每次调度请求生成一个单独的日志文件通过重写L
- 1、groupId从com.xxl改为com.xuxueli,为推送maven中央仓库做前期准备;
- 2、系统版本不在维护在项目跟pom中,各个子模块单独配置版本配置,解决子模块无法单独编译的问题;
- 3、底层RPC通讯,传输数据的字节长度统计规则优化,可节省50%数据传输量;
- 4、系统公共弹框功能,插件化;
- 5、底层表结构,表明统一大写;
- 6、调度中心,异常处理器JSON响应的ContentType修改,修复浏览器不识别的问题;
- 4、IJobHandler取消任务返回值,原通过返回值判断执行状态,逻辑改为:默认任务执行成功,仅在捕获异常时认定任务执行失败。
- 5、系统公共弹框功能,插件化;
- 6、底层表结构,表明统一大写;
- 7、调度中心,异常处理器JSON响应的ContentType修改,修复浏览器不识别的问题;
Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段, 地址见分支 [V1.3](https://github.com/xuxueli/xxl-job/tree/v1.3) 。新特性将会在master分支持续更新。

@ -169,15 +169,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.IJobHandler.JobHandleStatus;
public class DemoJobHandler extends IJobHandler {
private static transient Logger logger = LoggerFactory.getLogger(DemoJobHandler.class);
public class DemoGlueJobHandler extends IJobHandler {
private static transient Logger logger = LoggerFactory.getLogger(DemoGlueJobHandler.class);
@Override
public JobHandleStatus execute(String... params) throws Exception {
public void execute(String... params) throws Exception {
logger.info("XXL-JOB, Hello World.");
return JobHandleStatus.SUCCESS;
}
}

@ -2,7 +2,6 @@ package com.xxl.job.dao.impl;
import com.xxl.job.admin.core.model.XxlJobLog;
import com.xxl.job.admin.dao.IXxlJobLogDao;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.router.model.ResponseModel;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -45,7 +44,7 @@ public class XxlJobLogTest {
public void updateHandleInfo(){
XxlJobLog xxlJobLog = xxlJobLogDao.load(29);
xxlJobLog.setHandleTime(new Date());
xxlJobLog.setHandleStatus(IJobHandler.JobHandleStatus.SUCCESS.name());
xxlJobLog.setHandleStatus(ResponseModel.SUCCESS);
xxlJobLog.setHandleMsg("handle msg");
xxlJobLogDao.updateHandleInfo(xxlJobLog);
}

@ -1,10 +1,9 @@
package com.xxl.job.core.glue;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import javax.annotation.Resource;
import com.xxl.job.core.glue.cache.LocalCache;
import com.xxl.job.core.glue.loader.GlueLoader;
import com.xxl.job.core.handler.IJobHandler;
import groovy.lang.GroovyClassLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
@ -13,12 +12,9 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.annotation.AnnotationUtils;
import com.xxl.job.core.glue.cache.LocalCache;
import com.xxl.job.core.glue.loader.GlueLoader;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.IJobHandler.JobHandleStatus;
import groovy.lang.GroovyClassLoader;
import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
/**
* glue factory, product class/object by name
@ -157,8 +153,8 @@ public class GlueFactory implements ApplicationContextAware {
}
// ----------------------------- util -----------------------------
public static JobHandleStatus glue(String job_group, String job_name, String... params) throws Exception{
return GlueFactory.glueFactory.loadInstance(job_group, job_name).execute(params);
public static void glue(String job_group, String job_name, String... params) throws Exception{
GlueFactory.glueFactory.loadInstance(job_group, job_name).execute(params);
}
}

@ -12,20 +12,9 @@ public abstract class IJobHandler extends HandlerRouter {
* job handler <br><br>
* the return Object will be and stored
* @param params
* @return job status
* @return void, fail if catch exception
* @throws Exception
*/
public abstract JobHandleStatus execute(String... params) throws Exception;
public static enum JobHandleStatus{
/**
* handle success
*/
SUCCESS,
/**
* handle fail
*/
FAIL;
}
public abstract void execute(String... params) throws Exception;
}

@ -17,8 +17,8 @@ public class GlueJobHandler extends IJobHandler {
}
@Override
public JobHandleStatus execute(String... params) throws Exception {
return GlueFactory.glue(job_group, job_name, params);
public void execute(String... params) throws Exception {
GlueFactory.glue(job_group, job_name, params);
}
}

@ -1,9 +1,9 @@
package com.xxl.job.core.router.thread;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.IJobHandler.JobHandleStatus;
import com.xxl.job.core.log.XxlJobFileAppender;
import com.xxl.job.core.router.model.RequestModel;
import com.xxl.job.core.router.model.ResponseModel;
import org.eclipse.jetty.util.ConcurrentHashSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -74,15 +74,16 @@ public class JobThread extends Thread{
? (String[])(Arrays.asList(triggerDate.getExecutorParams().split(",")).toArray()) : null;
// handle job
JobHandleStatus _status = JobHandleStatus.FAIL;
String _status = ResponseModel.SUCCESS;
String _msg = null;
try {
XxlJobFileAppender.contextHolder.set(String.valueOf(triggerDate.getLogId()));
logger.info("----------- xxl-job job handle start -----------");
_status = handler.execute(handlerParams);
handler.execute(handlerParams);
} catch (Exception e) {
logger.info("JobThread Exception:", e);
_status = ResponseModel.FAIL;
StringWriter out = new StringWriter();
e.printStackTrace(new PrintWriter(out));
_msg = out.toString();
@ -93,12 +94,12 @@ public class JobThread extends Thread{
// callback handler info
if (!toStop) {
// commonm
triggerDate.setStatus(_status.name());
triggerDate.setStatus(_status);
triggerDate.setMsg(_msg);
TriggerCallbackThread.pushCallBack(triggerDate);
} else {
// is killed
triggerDate.setStatus(JobHandleStatus.FAIL.name());
triggerDate.setStatus(ResponseModel.FAIL);
triggerDate.setMsg(stopReason + " [业务运行中,被强制终止]");
TriggerCallbackThread.pushCallBack(triggerDate);
}
@ -113,7 +114,7 @@ public class JobThread extends Thread{
RequestModel triggerDate = triggerQueue.poll();
if (triggerDate!=null) {
// is killed
triggerDate.setStatus(JobHandleStatus.FAIL.name());
triggerDate.setStatus(ResponseModel.FAIL);
triggerDate.setMsg(stopReason + " [任务尚未执行,在调度队列中被终止]");
TriggerCallbackThread.pushCallBack(triggerDate);
}

@ -1,13 +1,12 @@
package com.xxl.job.executor.service.jobhandler;
import java.util.concurrent.TimeUnit;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHander;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHander;
import java.util.concurrent.TimeUnit;
/**
@ -26,14 +25,13 @@ public class DemoJobHandler extends IJobHandler {
private static transient Logger logger = LoggerFactory.getLogger(DemoJobHandler.class);
@Override
public JobHandleStatus execute(String... params) throws Exception {
public void execute(String... params) throws Exception {
logger.info("XXL-JOB, Hello World.");
for (int i = 0; i < 2; i++) {
logger.info("beat at:{}", i);
TimeUnit.SECONDS.sleep(2);
}
return JobHandleStatus.SUCCESS;
}
}

Loading…
Cancel
Save