新增Nutz执行器Sample示例项目;

pull/6/head
xuxueli 7 years ago
parent 004b4971fa
commit 06c72af187

@ -386,9 +386,11 @@ XXL-JOB是一个轻量级分布式任务调度框架其核心设计目标是
任务逻辑以JobHandler的形式存在于“执行器”所在项目中开发流程如下
#### 步骤一执行器项目中开发JobHandler
- 1、 新建一个继承com.xxl.job.core.handler.IJobHandler的Java类
- 2、 该类被Spring容器扫描为Bean实例如加“@Component”注解
- 3、 添加 “@JobHandler(value="自定义jobhandler名称")”注解注解的value值为自定义的JobHandler名称该名称对应的是调度中心新建任务的JobHandler属性的值。
- 1、继承"IJobHandler"“com.xxl.job.core.handler.IJobHandler”
- 2、注册到Spring容器添加“@Component”注解被Spring容器扫描为Bean实例
- 3、注册到执行器工厂添加“@JobHandler(value="自定义jobhandler名称")”注解注解value值对应的是调度中心新建任务的JobHandler属性的值。
- 4、执行日志需要通过 "XxlJobLogger.log" 打印执行日志;
可参考Sample示例执行器中的DemoJobHandler见下图
![输入图片说明](https://static.oschina.net/uploads/img/201607/23232347_oLlM.png "在这里输入图片标题")
@ -1073,32 +1075,33 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
- 10、任务日志文件路径时间戳格式化时SimpleDateFormat并发问题解决
### 6.20 版本 V1.9.0 特性[迭代中]
- 1、新增任务运行模式 "GLUE模式(NodeJS) "支持NodeJS脚本任务
- 2、脚本任务Shell、Python和Nodejs等支持获取分片参数
- 3、失败重试完整支持调度中心调度失败且启用"失败重试"策略时,将会自动重试一次;执行器执行失败且回调失败重试状态(新增失败重试状态返回值)时,也将会自动重试一次;
- 4、失败告警策略扩展默认提供邮件失败告警可扩展短信等扩展代码位置为 "JobFailMonitorHelper.failAlarm"
- 5、执行器端口支持自动生成(小于等于0时),避免端口定义冲突;
- 6、调度报表优化支持时间区间筛选
- 7、Log组件支持输出异常栈信息底层实现优化
- 8、告警邮件样式优化调整为表格形式邮件组件调整为commons-email简化邮件操作
- 9、项目依赖升级如spring、jackson等
- 10、任务日志记录发起调度的机器信息
- 11、交互优化如登陆注销
- 12、任务Cron长度扩展支持至128位支持负责类型Cron设置
- 13、执行器地址录入交互优化地址长度扩展支持至512位支持大规模执行器集群配置
- 14、任务参数“IJobHandler.execute”入参改为“String params”增强入参通用性。
- 15、JobHandler提供init/destroy方法支持在JobHandler初始化和销毁时进行附加操作
- 16、任务注解调整为 “@JobHandler”与任务抽象接口统一
- 17、修复任务监控线程被耗时任务阻塞的问题
- 18、修复任务监控线程无法监控任务触发和执行状态均未0的问题
- 19、执行器动态代理对象拦截非业务方法的执行
- 20、修复JobThread捕获Error错误不更新JobLog的问题
- 21、修复任务列表界面左侧菜单合并时样式错乱问题
- 22、调度中心项目日志配置改为xml文件格式
- 23、Log地址格式兼容支持非"/"结尾路径配置;
- 24、底层系统日志级别规范调整清理遗留代码
- 25、建表SQL优化支持同步创建制定编码的库和表
- 26、Nutz执行器Sample示例项目
- 1、新增Nutz执行器Sample示例项目
- 2、新增任务运行模式 "GLUE模式(NodeJS) "支持NodeJS脚本任务
- 3、脚本任务Shell、Python和Nodejs等支持获取分片参数
- 4、失败重试完整支持调度中心调度失败且启用"失败重试"策略时,将会自动重试一次;执行器执行失败且回调失败重试状态(新增失败重试状态返回值)时,也将会自动重试一次;
- 5、失败告警策略扩展默认提供邮件失败告警可扩展短信等扩展代码位置为 "JobFailMonitorHelper.failAlarm"
- 6、执行器端口支持自动生成(小于等于0时),避免端口定义冲突;
- 7、调度报表优化支持时间区间筛选
- 8、Log组件支持输出异常栈信息底层实现优化
- 9、告警邮件样式优化调整为表格形式邮件组件调整为commons-email简化邮件操作
- 10、项目依赖升级如spring、jackson等
- 11、任务日志记录发起调度的机器信息
- 12、交互优化如登陆注销
- 13、任务Cron长度扩展支持至128位支持负责类型Cron设置
- 14、执行器地址录入交互优化地址长度扩展支持至512位支持大规模执行器集群配置
- 15、任务参数“IJobHandler.execute”入参改为“String params”增强入参通用性。
- 16、JobHandler提供init/destroy方法支持在JobHandler初始化和销毁时进行附加操作
- 17、任务注解调整为 “@JobHandler”与任务抽象接口统一
- 18、修复任务监控线程被耗时任务阻塞的问题
- 19、修复任务监控线程无法监控任务触发和执行状态均未0的问题
- 20、执行器动态代理对象拦截非业务方法的执行
- 21、修复JobThread捕获Error错误不更新JobLog的问题
- 22、修复任务列表界面左侧菜单合并时样式错乱问题
- 23、调度中心项目日志配置改为xml文件格式
- 24、Log地址格式兼容支持非"/"结尾路径配置;
- 25、底层系统日志级别规范调整清理遗留代码
- 26、建表SQL优化支持同步创建制定编码的库和表
### TODO LIST

@ -17,8 +17,9 @@ public class JFinalCoreConfig extends JFinalConfig {
private Logger logger = LoggerFactory.getLogger(JFinalCoreConfig.class);
// ---------------------- xxl-job executor ----------------------
XxlJobExecutor xxlJobExecutor = null;
private XxlJobExecutor xxlJobExecutor = null;
private void initXxlJobExecutor() {
// registry jobhandler
XxlJobExecutor.registJobHandler("demoJobHandler", new DemoJobHandler());
XxlJobExecutor.registJobHandler("shardingJobHandler", new ShardingJobHandler());

@ -7,4 +7,5 @@ public class IndexController extends Controller {
public void index(){
renderText("xxl job executor running.");
}
}

@ -6,14 +6,13 @@ import com.xxl.job.core.log.XxlJobLogger;
import java.util.concurrent.TimeUnit;
/**
* HandlerDemoBean
* HandlerBean
*
*
* 1 IJobHandler
* 2 "XxlJobLogger.log"
* 3"JFinalCoreConfig" Jobhandler
* 1"IJobHandler"com.xxl.job.core.handler.IJobHandler
* 2 "JFinalCoreConfig.initXxlJobExecutor" keyJobHandler
* 3 "XxlJobLogger.log"
*
* @author xuxueli 2015-12-19 19:43:36
*/

@ -4,7 +4,7 @@ xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin
### xxl-job executor address
xxl.job.executor.appname=xxl-job-executor-sample
xxl.job.executor.ip=
xxl.job.executor.port=9997
xxl.job.executor.port=9996
### xxl-job log path
xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler

@ -3,6 +3,7 @@
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>xxl-job-executor-sample-jfinal</display-name>
<context-param>
<param-name>webAppRootKey</param-name>
@ -23,4 +24,9 @@
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>

@ -1,26 +1,23 @@
package com.xuxueli.executor.sample.nutz;
import org.nutz.mvc.annotation.Encoding;
import org.nutz.mvc.annotation.Fail;
import org.nutz.mvc.annotation.IocBy;
import org.nutz.mvc.annotation.Localization;
import org.nutz.mvc.annotation.Modules;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.SetupBy;
import com.xuxueli.executor.sample.nutz.config.NutzSetup;
import org.nutz.mvc.annotation.*;
import org.nutz.mvc.ioc.provider.ComboIocProvider;
/**
* nutz module
*
* @author
*
* @author xuxueli 2017-12-25 17:58:43
*/
@IocBy(type=ComboIocProvider.class,args={"*org.nutz.ioc.loader.json.JsonLoader","ioc/",
"*org.nutz.ioc.loader.annotation.AnnotationIocLoader","com.xuxueli"})
@IocBy(type = ComboIocProvider.class,
args = {"*org.nutz.ioc.loader.annotation.AnnotationIocLoader",
"com.xuxueli.executor.sample.nutz"})
@Encoding(input = "utf-8", output = "utf-8")
@Modules(scanPackage = true)
@Localization("msg")
@Ok("json")
@Fail("json")
@SetupBy(MainSetup.class)
@SetupBy(NutzSetup.class)
public class MainModule {
}

@ -1,33 +1,41 @@
package com.xuxueli.executor.sample.nutz;
package com.xuxueli.executor.sample.nutz.config;
import org.nutz.ioc.IocException;
import com.xxl.job.core.executor.XxlJobExecutor;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.NutConfig;
import org.nutz.mvc.Setup;
import com.xxl.job.core.executor.XxlJobExecutor;
import com.xxl.job.core.handler.IJobHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* nutz setup
*
* @author
*
* @author xuxueli 2017-12-25 17:58:43
*/
public class MainSetup implements Setup {
public static final Log log = Logs.get();
XxlJobExecutor xxlJobExecutor = null;
public class NutzSetup implements Setup {
private Logger logger = LoggerFactory.getLogger(NutzSetup.class);
//public static final Log logger = Logs.get();
private XxlJobExecutor xxlJobExecutor = null;
@Override
public void init(NutConfig cfg) {
// 通用注册IJobHandler
String[] names = cfg.getIoc().getNamesByType(IJobHandler.class);
for (String name : names) {
XxlJobExecutor.registJobHandler(name, cfg.getIoc().get(IJobHandler.class, name));
// regist JobHandler
String[] beanNames = cfg.getIoc().getNamesByType(IJobHandler.class);
if (beanNames==null || beanNames.length==0) {
return;
}
for (String beanName : beanNames) {
IJobHandler jobHandler = cfg.getIoc().get(IJobHandler.class, beanName);
String name = jobHandler.getClass().getAnnotation(JobHandler.class).value();
XxlJobExecutor.registJobHandler(name, jobHandler);
}
// load executor prop
PropertiesProxy xxlJobProp = cfg.getIoc().get(PropertiesProxy.class, "conf");
PropertiesProxy xxlJobProp = new PropertiesProxy("xxl-job-executor.properties");
// init executor
xxlJobExecutor = new XxlJobExecutor();
@ -42,7 +50,7 @@ public class MainSetup implements Setup {
try {
xxlJobExecutor.start();
} catch (Exception e) {
log.error(e.getMessage(), e);
logger.error(e.getMessage(), e);
}
}
@ -52,4 +60,5 @@ public class MainSetup implements Setup {
xxlJobExecutor.destroy();
}
}
}

@ -1,36 +1,38 @@
package com.xuxueli.executor.sample.nutz.jobhandler;
import java.util.concurrent.TimeUnit;
import org.nutz.ioc.loader.annotation.IocBean;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import org.nutz.ioc.loader.annotation.IocBean;
import java.util.concurrent.TimeUnit;
/**
* HandlerDemoBean
* HandlerBean
*
*
* 1 IJobHandler
* 2 "XxlJobLogger.log"
* 3 "JFinalCoreConfig" Jobhandler
* 1"IJobHandler"com.xxl.job.core.handler.IJobHandler
* 2Nutz@IocBeanNutzBean
* 3@JobHandler(value="自定义jobhandler名称")valueJobHandler
* 4 "XxlJobLogger.log"
*
* @author xuxueli 2015-12-19 19:43:36
*/
@JobHandler(value="demoJobHandler")
@IocBean
public class DemoJobHandler extends IJobHandler {
@Override
public ReturnT<String> execute(String... params) throws Exception {
public ReturnT<String> execute(String param) throws Exception {
XxlJobLogger.log("XXL-JOB, Hello World.");
for (int i = 0; i < 5; i++) {
XxlJobLogger.log("beat at:" + i);
TimeUnit.SECONDS.sleep(2);
}
return ReturnT.SUCCESS;
return SUCCESS;
}
}

@ -1,5 +1,6 @@
package com.xuxueli.executor.sample.nutz.jobhandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import org.nutz.ioc.loader.annotation.IocBean;
import com.xxl.job.core.biz.model.ReturnT;
@ -7,17 +8,17 @@ import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import com.xxl.job.core.util.ShardingUtil;
/**
* 广
*
* @author xuxueli 2017-07-25 20:56:50
*/
@JobHandler(value="shardingJobHandler")
@IocBean
public class ShardingJobHandler extends IJobHandler {
@Override
public ReturnT<String> execute(String... params) throws Exception {
public ReturnT<String> execute(String param) throws Exception {
// 分片参数
ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo();
@ -32,7 +33,7 @@ public class ShardingJobHandler extends IJobHandler {
}
}
return ReturnT.SUCCESS;
return SUCCESS;
}
}

@ -3,16 +3,14 @@ package com.xuxueli.executor.sample.nutz.module;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
/**
*
* @author
*
*/
@IocBean
public class IndexModule {
@At
@Ok("jsp:index")
public void index() {
@At("/")
@Ok("json")
public String index() {
return "xxl job executor running.";
}
}

@ -1,38 +0,0 @@
var ioc = {
conf : {
type : "org.nutz.ioc.impl.PropertiesProxy",
fields : {
paths : [ "custom/" ]
}
},
/**
* job
*/
/*xxlJobExecutor : {
type : "com.xxl.job.core.executor.XxlJobExecutor",
events : {
create : "start",
depose : "destroy"
},
fields : {
ip : {
java : "$conf.get('xxl.job.executor.ip')"
},
port : {
java : "$conf.get('xxl.job.executor.port')"
},
appName : {
java : "$conf.get('xxl.job.executor.appname')"
},
adminAddresses : {
java : "$conf.get('xxl.job.admin.addresses')"
},
logPath : {
java : "$conf.get('xxl.job.executor.logpath')"
},
accessToken : {
java : "$conf.get('xxl.job.accessToken')"
}
}
}*/
};

@ -5,16 +5,16 @@
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss} spider-executor [%c]-[%t]-[%M]-[%L]-[%p] %m%n"/>
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss} xxl-job-executor-sample-nutz [%c]-[%t]-[%M]-[%L]-[%p] %m%n"/>
</layout>
</appender>
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="file" value="/data/applogs/xxl-job/spider-executor.log"/>
<param name="file" value="/data/applogs/xxl-job/xxl-job-executor-sample-nutz.log"/>
<param name="append" value="true"/>
<param name="encoding" value="UTF-8"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss} spider-executor [%c]-[%t]-[%M]-[%L]-[%p] %m%n"/>
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss} xxl-job-executor-sample-nutz [%c]-[%t]-[%M]-[%L]-[%p] %m%n"/>
</layout>
</appender>

@ -4,10 +4,10 @@ xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin
### xxl-job executor address
xxl.job.executor.appname=xxl-job-executor-sample
xxl.job.executor.ip=
xxl.job.executor.port=1024
xxl.job.executor.port=9997
### xxl-job log path
xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler/
xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler
### xxl-job, access token
xxl.job.accessToken=

@ -1,12 +0,0 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>nutz 执行器启动成功</title>
</head>
<body>
nutz 执行器启动成功!
</body>
</html>

@ -3,9 +3,16 @@
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>xxl-job-executor-sample-nutz</display-name>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>xxl-job-executor-sample-nutz</param-value>
</context-param>
<!-- nutz -->
<filter>
<filter-name>xxl-job-executor-sample-nutz</filter-name>
<filter-name>nutz</filter-name>
<filter-class>org.nutz.mvc.NutFilter</filter-class>
<init-param>
<param-name>modules</param-name>
@ -13,10 +20,13 @@
</init-param>
</filter>
<filter-mapping>
<filter-name>xxl-job-executor-sample-nutz</filter-name>
<filter-name>nutz</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>

@ -10,12 +10,12 @@ import java.util.concurrent.TimeUnit;
/**
* HandlerDemoBean
* HandlerBean
*
*
* 1com.xxl.job.core.handler.IJobHandlerJava
* 2SpringBean@Component
* 3 @JobHandler(value="自定义jobhandler名称")valueJobHandlerJobHandler
* 1"IJobHandler"com.xxl.job.core.handler.IJobHandler
* 2Spring@ComponentSpringBean
* 3@JobHandler(value="自定义jobhandler名称")valueJobHandler
* 4 "XxlJobLogger.log"
*
* @author xuxueli 2015-12-19 19:43:36

@ -3,12 +3,14 @@
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>xxl-job-executor-sample-spring</display-name>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>xxl-job-executor-sample-spring</param-value>
</context-param>
<!-- spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationcontext-*.xml</param-value>
@ -21,6 +23,7 @@
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

@ -10,12 +10,12 @@ import java.util.concurrent.TimeUnit;
/**
* HandlerDemoBean
* HandlerBean
*
*
* 1com.xxl.job.core.handler.IJobHandlerJava
* 2SpringBean@Component
* 3 @JobHandler(value="自定义jobhandler名称")valueJobHandlerJobHandler
* 1"IJobHandler"com.xxl.job.core.handler.IJobHandler
* 2Spring@ComponentSpringBean
* 3@JobHandler(value="自定义jobhandler名称")valueJobHandler
* 4 "XxlJobLogger.log"
*
* @author xuxueli 2015-12-19 19:43:36

@ -11,7 +11,7 @@ xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin
### xxl-job executor address
xxl.job.executor.appname=xxl-job-executor-sample
xxl.job.executor.ip=
xxl.job.executor.port=-1
xxl.job.executor.port=9998
### xxl-job log path
xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler

Loading…
Cancel
Save