Parcourir la source

任务触发时支持动态传参,调度中心与API服务均提供提供动态参数功能

xuxueli il y a 7 ans
Parent
révision
67fc5a1895

+ 3 - 4
doc/XXL-JOB官方文档.md Voir le fichier

@@ -1283,7 +1283,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
1283 1283
 - 33、修复表字段 “t.order”与数据库关键字冲突查询失败的问题,
1284 1284
 - 34、调度中心提供API服务,支持通过API服务对任务进行查询、新增、更新、启停等操作;
1285 1285
 - 35、分片任务失败重试优化,仅重试当前失败的分片;
1286
-- 36、任务参数数据框调整,手动触发时支持动态输入参数
1286
+- 36、任务触发时支持动态传参,调度中心与API服务均提供提供动态参数功能
1287 1287
 
1288 1288
 
1289 1289
 ### TODO LIST
@@ -1298,7 +1298,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
1298 1298
 - 9、执行器Log清理功能:调度中心Log删除时同步删除执行器中的Log文件;
1299 1299
 - 10、Bean模式任务,JobHandler自动从执行器中查询展示为下拉框,选择后自动填充任务名称等属性;
1300 1300
 - 11、API事件触发类型任务(更类似MQ消息)支持"动态传参、延时消费";该类型任务不走Quartz,单独建立MQ消息表,调度中心竞争触发;待定,该功能与 XXL-MQ 冲突,该场景建议用后者;
1301
-- 12、API任务触发时支持动态传参
1301
+- 12、调度线程池改为协程方式实现,大幅降低系统内存消耗
1302 1302
 - 13、任务依赖增强,新增任务类型 "流程任务",流程节点可挂载普通类型任务,承担任务依赖功能。现有子任务模型取消;需要考虑任务依赖死循环问题;
1303 1303
 - 14、任务告警逻辑调整:任务调度,以及任务回调失败时,均推送监控队列。后期考虑通过任务Log字段控制告警状态;
1304 1304
 - 15、新增任务默认运行状态,任务更新时运行状态保持不变;
@@ -1306,8 +1306,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
1306 1306
 - 17、注册中心支持扩展,除默认基于DB之外,支持扩展接入第三方注册中心如zk、eureka等;
1307 1307
 - 18、流程任务,支持参数传递;
1308 1308
 - 19、SimpleTrigger 支持;
1309
-- 20、调度线程池改为协程方式实现,大幅降低系统内存消耗;
1310
-- 21、Release发布时,一同发布调度中心安装包,真正实现开箱即用;
1309
+- 20、Release发布时,一同发布调度中心安装包,真正实现开箱即用;
1311 1310
 
1312 1311
 ## 七、其他
1313 1312
 

+ 7 - 2
xxl-job-admin/src/main/java/com/xxl/job/admin/controller/JobInfoController.java Voir le fichier

@@ -91,8 +91,13 @@ public class JobInfoController {
91 91
 	@RequestMapping("/trigger")
92 92
 	@ResponseBody
93 93
 	//@PermessionLimit(limit = false)
94
-	public ReturnT<String> triggerJob(int id) {
95
-		JobTriggerPoolHelper.trigger(id, TriggerTypeEnum.MANUAL, -1, null);
94
+	public ReturnT<String> triggerJob(int id, String executorParam) {
95
+		// force cover job param
96
+		if (executorParam == null) {
97
+			executorParam = "";
98
+		}
99
+
100
+		JobTriggerPoolHelper.trigger(id, TriggerTypeEnum.MANUAL, -1, null, executorParam);
96 101
 		return ReturnT.SUCCESS;
97 102
 	}
98 103
 	

+ 1 - 1
xxl-job-admin/src/main/java/com/xxl/job/admin/core/jobbean/RemoteHttpJobBean.java Voir le fichier

@@ -29,7 +29,7 @@ public class RemoteHttpJobBean extends QuartzJobBean {
29 29
 
30 30
 		// trigger
31 31
 		//XxlJobTrigger.trigger(jobId);
32
-		JobTriggerPoolHelper.trigger(jobId, TriggerTypeEnum.CRON, -1, null);
32
+		JobTriggerPoolHelper.trigger(jobId, TriggerTypeEnum.CRON, -1, null, null);
33 33
 	}
34 34
 
35 35
 }

+ 1 - 1
xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobFailMonitorHelper.java Voir le fichier

@@ -73,7 +73,7 @@ public class JobFailMonitorHelper {
73 73
 									XxlJobInfo info = XxlJobDynamicScheduler.xxlJobInfoDao.loadById(log.getJobId());
74 74
 
75 75
 									if (log.getExecutorFailRetryCount() > 0) {
76
-										JobTriggerPoolHelper.trigger(log.getJobId(), TriggerTypeEnum.RETRY, (log.getExecutorFailRetryCount()-1), log.getExecutorShardingParam());
76
+										JobTriggerPoolHelper.trigger(log.getJobId(), TriggerTypeEnum.RETRY, (log.getExecutorFailRetryCount()-1), log.getExecutorShardingParam(), null);
77 77
 										String retryMsg = "<br><br><span style=\"color:#F39C12;\" > >>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_type_retry") +"<<<<<<<<<<< </span><br>";
78 78
 										log.setTriggerMsg(log.getTriggerMsg() + retryMsg);
79 79
 										XxlJobDynamicScheduler.xxlJobLogDao.updateTriggerInfo(log);

+ 9 - 5
xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobTriggerPoolHelper.java Voir le fichier

@@ -29,11 +29,11 @@ public class JobTriggerPoolHelper {
29 29
             new ThreadPoolExecutor.CallerRunsPolicy());
30 30
 
31 31
 
32
-    public void addTrigger(final int jobId, final TriggerTypeEnum triggerType, final int failRetryCount, final String executorShardingParam) {
32
+    public void addTrigger(final int jobId, final TriggerTypeEnum triggerType, final int failRetryCount, final String executorShardingParam, final String executorParam) {
33 33
         triggerPool.execute(new Runnable() {
34 34
             @Override
35 35
             public void run() {
36
-                XxlJobTrigger.trigger(jobId, triggerType, failRetryCount, executorShardingParam);
36
+                XxlJobTrigger.trigger(jobId, triggerType, failRetryCount, executorShardingParam, executorParam);
37 37
             }
38 38
         });
39 39
     }
@@ -50,13 +50,17 @@ public class JobTriggerPoolHelper {
50 50
 
51 51
     /**
52 52
      * @param jobId
53
+     * @param triggerType
53 54
      * @param failRetryCount
54 55
      * 			>=0: use this param
55 56
      * 			<0: use param from job info config
56
-     *
57
+     * @param executorShardingParam
58
+     * @param executorParam
59
+     *          null: use job param
60
+     *          not null: cover job param
57 61
      */
58
-    public static void trigger(int jobId, TriggerTypeEnum triggerType, int failRetryCount, String executorShardingParam) {
59
-        helper.addTrigger(jobId, triggerType, failRetryCount, executorShardingParam);
62
+    public static void trigger(int jobId, TriggerTypeEnum triggerType, int failRetryCount, String executorShardingParam, String executorParam) {
63
+        helper.addTrigger(jobId, triggerType, failRetryCount, executorShardingParam, executorParam);
60 64
     }
61 65
 
62 66
     public static void toStop() {

+ 9 - 2
xxl-job-admin/src/main/java/com/xxl/job/admin/core/trigger/XxlJobTrigger.java Voir le fichier

@@ -30,18 +30,25 @@ public class XxlJobTrigger {
30 30
      * trigger job
31 31
      *
32 32
      * @param jobId
33
+     * @param triggerType
33 34
      * @param failRetryCount
34 35
      * 			>=0: use this param
35 36
      * 			<0: use param from job info config
36
-     *
37
+     * @param executorShardingParam
38
+     * @param executorParam
39
+     *          null: use job param
40
+     *          not null: cover job param
37 41
      */
38
-    public static void trigger(int jobId, TriggerTypeEnum triggerType, int failRetryCount, String executorShardingParam) {
42
+    public static void trigger(int jobId, TriggerTypeEnum triggerType, int failRetryCount, String executorShardingParam, String executorParam) {
39 43
         // load data
40 44
         XxlJobInfo jobInfo = XxlJobDynamicScheduler.xxlJobInfoDao.loadById(jobId);
41 45
         if (jobInfo == null) {
42 46
             logger.warn(">>>>>>>>>>>> trigger fail, jobId invalid,jobId={}", jobId);
43 47
             return;
44 48
         }
49
+        if (executorParam != null) {
50
+            jobInfo.setExecutorParam(executorParam);
51
+        }
45 52
         int finalFailRetryCount = failRetryCount>=0?failRetryCount:jobInfo.getExecutorFailRetryCount();
46 53
         XxlJobGroup group = XxlJobDynamicScheduler.xxlJobGroupDao.load(jobInfo.getJobGroup());
47 54
 

+ 1 - 1
xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java Voir le fichier

@@ -71,7 +71,7 @@ public class AdminBizImpl implements AdminBiz {
71 71
                     int childJobId = (StringUtils.isNotBlank(childJobIds[i]) && StringUtils.isNumeric(childJobIds[i]))?Integer.valueOf(childJobIds[i]):-1;
72 72
                     if (childJobId > 0) {
73 73
 
74
-                        JobTriggerPoolHelper.trigger(childJobId, TriggerTypeEnum.PARENT, 0, null);
74
+                        JobTriggerPoolHelper.trigger(childJobId, TriggerTypeEnum.PARENT, 0, null, null);
75 75
                         ReturnT<String> triggerChildResult = ReturnT.SUCCESS;
76 76
 
77 77
                         // add msg

+ 29 - 0
xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/jobinfo.index.ftl Voir le fichier

@@ -380,6 +380,35 @@ exit 0
380 380
 	</div>
381 381
 </div>
382 382
 
383
+<#-- trigger -->
384
+<div class="modal fade" id="jobTriggerModal" tabindex="-1" role="dialog"  aria-hidden="true">
385
+    <div class="modal-dialog ">
386
+        <div class="modal-content">
387
+            <div class="modal-header">
388
+                <h4 class="modal-title" >${I18n.jobinfo_opt_run}</h4>
389
+            </div>
390
+            <div class="modal-body">
391
+                <form class="form-horizontal form" role="form" >
392
+                    <div class="form-group">
393
+                        <label for="firstname" class="col-sm-2 control-label">${I18n.jobinfo_field_executorparam}<font color="black">*</font></label>
394
+                        <div class="col-sm-10">
395
+                            <textarea class="textarea form-control" name="executorParam" placeholder="${I18n.system_please_input}${I18n.jobinfo_field_executorparam}" maxlength="512" style="height: 63px; line-height: 1.2;"></textarea>
396
+                        </div>
397
+                    </div>
398
+                    <hr>
399
+                    <div class="form-group">
400
+                        <div class="col-sm-offset-3 col-sm-6">
401
+                            <button type="button" class="btn btn-primary ok" >${I18n.system_save}</button>
402
+                            <button type="button" class="btn btn-default" data-dismiss="modal">${I18n.system_cancel}</button>
403
+                            <input type="hidden" name="id" >
404
+                        </div>
405
+                    </div>
406
+                </form>
407
+            </div>
408
+        </div>
409
+    </div>
410
+</div>
411
+
383 412
 <@netCommon.commonScript />
384 413
 <!-- DataTables -->
385 414
 <script src="${request.contextPath}/static/adminlte/plugins/datatables/jquery.dataTables.min.js"></script>

+ 45 - 4
xxl-job-admin/src/main/webapp/static/js/jobinfo.index.1.js Voir le fichier

@@ -122,7 +122,7 @@ $(function() {
122 122
 								// html
123 123
                                 tableData['key'+row.id] = row;
124 124
 								var html = '<p id="'+ row.id +'" >'+
125
-									'<button class="btn btn-primary btn-xs job_operate" _type="job_trigger" type="button">'+ I18n.jobinfo_opt_run +'</button>  '+
125
+									'<button class="btn btn-primary btn-xs job_trigger" type="button">'+ I18n.jobinfo_opt_run +'</button>  '+
126 126
 									pause_resume +
127 127
 									'<button class="btn btn-primary btn-xs" type="job_del" type="button" onclick="javascript:window.open(\'' + logUrl + '\')" >'+ I18n.jobinfo_opt_log +'</button><br>  '+
128 128
 									'<button class="btn btn-warning btn-xs update" type="button">'+ I18n.system_opt_edit +'</button>  '+
@@ -195,9 +195,6 @@ $(function() {
195 195
 			typeName = I18n.system_opt_del ;
196 196
 			url = base_url + "/jobinfo/remove";
197 197
 			needFresh = true;
198
-		} else if ("job_trigger" == type) {
199
-			typeName = I18n.jobinfo_opt_run ;
200
-			url = base_url + "/jobinfo/trigger";
201 198
 		} else {
202 199
 			return;
203 200
 		}
@@ -246,6 +243,50 @@ $(function() {
246 243
 		});
247 244
 	});
248 245
 
246
+    // job trigger
247
+    $("#job_list").on('click', '.job_trigger',function() {
248
+        var id = $(this).parent('p').attr("id");
249
+        var row = tableData['key'+id];
250
+
251
+        $("#jobTriggerModal .form input[name='id']").val( row.id );
252
+        $("#jobTriggerModal .form textarea[name='executorParam']").val( row.executorParam );
253
+
254
+        $('#jobTriggerModal').modal({backdrop: false, keyboard: false}).modal('show');
255
+    });
256
+    $("#jobTriggerModal .ok").on('click',function() {
257
+        $.ajax({
258
+            type : 'POST',
259
+            url : base_url + "/jobinfo/trigger",
260
+            data : {
261
+                "id" : $("#jobTriggerModal .form input[name='id']").val(),
262
+                "executorParam" : $("#jobTriggerModal .textarea[name='executorParam']").val()
263
+            },
264
+            dataType : "json",
265
+            success : function(data){
266
+                if (data.code == 200) {
267
+                    $('#jobTriggerModal').modal('hide');
268
+
269
+                    layer.open({
270
+                        title: I18n.system_tips,
271
+                        btn: [ I18n.system_ok ],
272
+                        content: I18n.jobinfo_opt_run + I18n.system_success ,
273
+                        icon: '1'
274
+                    });
275
+                } else {
276
+                    layer.open({
277
+                        title: I18n.system_tips,
278
+                        btn: [ I18n.system_ok ],
279
+                        content: (data.msg || I18n.jobinfo_opt_run + I18n.system_fail ),
280
+                        icon: '2'
281
+                    });
282
+                }
283
+            }
284
+        });
285
+    });
286
+    $("#jobTriggerModal").on('hide.bs.modal', function () {
287
+        $("#jobTriggerModal .form")[0].reset();
288
+    });
289
+
249 290
 	// add
250 291
 	$(".add").click(function(){
251 292
 		$('#addModal').modal({backdrop: false, keyboard: false}).modal('show');