Browse Source

功能完善:

xueli.xue 9 years ago
parent
commit
168050dcda

+ 8 - 0
README.md View File

71
 	2、执行器异步回调执行日志;
71
 	2、执行器异步回调执行日志;
72
 	3、【重要】在 “调度中心” 支持HA的基础上,扩展执行器的Failover支持,支持配置多执行期地址;
72
 	3、【重要】在 “调度中心” 支持HA的基础上,扩展执行器的Failover支持,支持配置多执行期地址;
73
 
73
 
74
+# 规划中
75
+	1、任务终止时,任务队列中调度回调通过被终止的接口;
76
+	2、任务执行规则自定义:假如前一个任务正在执行,后续调度执行规则支持自定义;
77
+		串行(默认,当前逻辑):后续调度入调度队列;
78
+		并行:后续调度并行执行;
79
+		Pass:后续调度被Pass;
80
+
74
 # 源码目录说明
81
 # 源码目录说明
75
 	/xxl-job-admin					【调度中心】:负责管理调度信息,按照调度配置发出调度请求;
82
 	/xxl-job-admin					【调度中心】:负责管理调度信息,按照调度配置发出调度请求;
76
 	/xxl-job-core					公共依赖
83
 	/xxl-job-core					公共依赖
87
 	4、人人聚财金服;
94
 	4、人人聚财金服;
88
 	5、……
95
 	5、……
89
 	更多接入公司,欢迎在https://github.com/xuxueli/xxl-job/issues/1 登记。
96
 	更多接入公司,欢迎在https://github.com/xuxueli/xxl-job/issues/1 登记。
97
+	

+ 12 - 1
xxl-job-admin/src/main/java/com/xxl/job/admin/core/callback/XxlJobLogCallbackServer.java View File

22
 		return trigger_log_address;
22
 		return trigger_log_address;
23
 	}
23
 	}
24
     
24
     
25
+    Server server = null;
25
     public void start(int callBackPort) throws Exception {
26
     public void start(int callBackPort) throws Exception {
26
     	// init address
27
     	// init address
27
     	
28
     	
32
         new Thread(new Runnable() {
33
         new Thread(new Runnable() {
33
             @Override
34
             @Override
34
             public void run() {
35
             public void run() {
35
-                Server server = new Server();
36
+                server = new Server();
36
                 server.setThreadPool(new ExecutorThreadPool(200, 200, 30000));	// 非阻塞
37
                 server.setThreadPool(new ExecutorThreadPool(200, 200, 30000));	// 非阻塞
37
 
38
 
38
                 // connector
39
                 // connector
59
 
60
 
60
     }
61
     }
61
 
62
 
63
+	public void destroy() {
64
+		if (server!=null) {
65
+			try {
66
+				server.stop();
67
+			} catch (Exception e) {
68
+				e.printStackTrace();
69
+			}
70
+		}
71
+	}
72
+
62
 }
73
 }

+ 10 - 1
xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/DynamicSchedulerUtil.java View File

55
 	}
55
 	}
56
     
56
     
57
     // init
57
     // init
58
+    XxlJobLogCallbackServer xxlJobLogCallbackServer = null;
58
     public void init(){
59
     public void init(){
59
     	try {
60
     	try {
60
     		// start callback server
61
     		// start callback server
61
-			new XxlJobLogCallbackServer().start(callBackPort);
62
+    		xxlJobLogCallbackServer = new XxlJobLogCallbackServer();
63
+    		xxlJobLogCallbackServer.start(callBackPort);
62
 		} catch (Exception e) {
64
 		} catch (Exception e) {
63
 			e.printStackTrace();
65
 			e.printStackTrace();
64
 		}
66
 		}
65
     }
67
     }
66
     
68
     
69
+    // destroy
70
+    public void destroy(){
71
+    	if (xxlJobLogCallbackServer!=null) {
72
+    		xxlJobLogCallbackServer.destroy();
73
+		}
74
+    }
75
+    
67
     // xxlJobLogDao、xxlJobInfoDao
76
     // xxlJobLogDao、xxlJobInfoDao
68
     public static IXxlJobLogDao xxlJobLogDao;
77
     public static IXxlJobLogDao xxlJobLogDao;
69
     public static IXxlJobInfoDao xxlJobInfoDao;
78
     public static IXxlJobInfoDao xxlJobInfoDao;

+ 1 - 1
xxl-job-admin/src/main/resources/applicationcontext-xxl-job.xml View File

18
 	</bean>
18
 	</bean>
19
 	
19
 	
20
 	<!-- 协同-调度器 -->
20
 	<!-- 协同-调度器 -->
21
-	<bean id="dynamicSchedulerUtil" class="com.xxl.job.admin.core.util.DynamicSchedulerUtil" init-method="init">
21
+	<bean id="dynamicSchedulerUtil" class="com.xxl.job.admin.core.util.DynamicSchedulerUtil" init-method="init" destroy-method="destroy" >
22
 		<!-- (轻易不要变更“调度器名称”, 任务创建时会绑定该“调度器名称”) -->
22
 		<!-- (轻易不要变更“调度器名称”, 任务创建时会绑定该“调度器名称”) -->
23
         <property name="scheduler" ref="quartzScheduler"/>
23
         <property name="scheduler" ref="quartzScheduler"/>
24
         <property name="callBackPort" value="8888"/>
24
         <property name="callBackPort" value="8888"/>

+ 14 - 1
xxl-job-core/src/main/java/com/xxl/job/core/executor/jetty/XxlJobExecutor.java View File

29
         this.port = port;
29
         this.port = port;
30
     }
30
     }
31
 
31
 
32
+    // ---------------------------------- job server ------------------------------------
33
+    Server server = null;
32
     public void start() throws Exception {
34
     public void start() throws Exception {
33
 
35
 
34
         new Thread(new Runnable() {
36
         new Thread(new Runnable() {
35
             @Override
37
             @Override
36
             public void run() {
38
             public void run() {
37
-                Server server = new Server();
39
+                server = new Server();
38
                 server.setThreadPool(new ExecutorThreadPool(200, 200, 30000));	// 非阻塞
40
                 server.setThreadPool(new ExecutorThreadPool(200, 200, 30000));	// 非阻塞
39
 
41
 
40
                 // connector
42
                 // connector
60
         }).start();
62
         }).start();
61
 
63
 
62
     }
64
     }
65
+    
66
+    public void destroy(){
67
+    	if (server!=null) {
68
+    		try {
69
+				server.stop();
70
+			} catch (Exception e) {
71
+				e.printStackTrace();
72
+			}
73
+		}
74
+    }
63
 
75
 
76
+    // ---------------------------------- init job handler ------------------------------------
64
     public static ApplicationContext applicationContext;
77
     public static ApplicationContext applicationContext;
65
 	@Override
78
 	@Override
66
 	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
79
 	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

+ 22 - 0
xxl-job-core/src/main/java/com/xxl/job/core/handler/HandlerThread.java View File

96
 						params.put("status", _status.name());
96
 						params.put("status", _status.name());
97
 						params.put("msg", _msg);
97
 						params.put("msg", _msg);
98
 						HandlerRepository.pushCallBack(HttpUtil.addressToUrl(log_address), params);
98
 						HandlerRepository.pushCallBack(HttpUtil.addressToUrl(log_address), params);
99
+					} else {
100
+						HashMap<String, String> params = new HashMap<String, String>();
101
+						params.put("log_id", log_id);
102
+						params.put("status", JobHandleStatus.FAIL.name());
103
+						params.put("msg", "人工手动终止[业务运行中,被强制终止]");
104
+						HandlerRepository.pushCallBack(HttpUtil.addressToUrl(log_address), params);
99
 					}
105
 					}
100
 				} else {
106
 				} else {
101
 					i++;
107
 					i++;
113
 				logger.info("HandlerThread Exception:", e);
119
 				logger.info("HandlerThread Exception:", e);
114
 			}
120
 			}
115
 		}
121
 		}
122
+		
123
+		// callback trigger request in queue
124
+		while(handlerDataQueue!=null && handlerDataQueue.size()>0){
125
+			Map<String, String> handlerData = handlerDataQueue.poll();
126
+			if (handlerData!=null) {
127
+				String log_address = handlerData.get(HandlerParamEnum.LOG_ADDRESS.name());
128
+				String log_id = handlerData.get(HandlerParamEnum.LOG_ID.name());
129
+				
130
+				HashMap<String, String> params = new HashMap<String, String>();
131
+				params.put("log_id", log_id);
132
+				params.put("status", JobHandleStatus.FAIL.name());
133
+				params.put("msg", "人工手动终止[任务尚未执行,在调度队列中被终止]");
134
+				HandlerRepository.pushCallBack(HttpUtil.addressToUrl(log_address), params);
135
+			}
136
+		}
137
+		
116
 		logger.info(">>>>>>>>>>>> xxl-job handlerThrad stoped, hashCode:{}", Thread.currentThread());
138
 		logger.info(">>>>>>>>>>>> xxl-job handlerThrad stoped, hashCode:{}", Thread.currentThread());
117
 	}
139
 	}
118
 }
140
 }

+ 1 - 1
xxl-job-executor-example/src/main/resources/applicationcontext-xxl-job.xml View File

12
 	<context:component-scan base-package="com.xxl.job.executor" />
12
 	<context:component-scan base-package="com.xxl.job.executor" />
13
 
13
 
14
 	<!-- 执行器 -->
14
 	<!-- 执行器 -->
15
-	<bean id="xxlJobExecutor" class="com.xxl.job.core.executor.jetty.XxlJobExecutor" init-method="start">
15
+	<bean id="xxlJobExecutor" class="com.xxl.job.core.executor.jetty.XxlJobExecutor" init-method="start" destroy-method="destroy" >
16
 		<property name="port" value="9999" />
16
 		<property name="port" value="9999" />
17
 	</bean>
17
 	</bean>
18
 	
18