@@ -51,6 +51,8 @@ public class JobTrigger {
5151 * >=0: use this param
5252 * <0: use param from job info config
5353 * @param executorShardingParam
54+ * null: new sharding, all nodes
55+ * not null: for retry, only one node
5456 * @param executorParam
5557 * null: use job param
5658 * not null: cover job param
@@ -85,6 +87,7 @@ public void trigger(int jobId,
8587
8688 // sharding param
8789 int [] shardingParam = null ;
90+ Date triggerTime = new Date ();
8891 if (executorShardingParam !=null ){
8992 String [] shardingArr = executorShardingParam .split ("/" );
9093 if (shardingArr .length ==2 && StringTool .isNumeric (shardingArr [0 ]) && StringTool .isNumeric (shardingArr [1 ])) {
@@ -97,13 +100,13 @@ public void trigger(int jobId,
97100 && group .getRegistryList ()!=null && !group .getRegistryList ().isEmpty ()
98101 && shardingParam ==null ) {
99102 for (int i = 0 ; i < group .getRegistryList ().size (); i ++) {
100- processTrigger (group , jobInfo , finalFailRetryCount , triggerType , i , group .getRegistryList ().size ());
103+ processTrigger (group , jobInfo , finalFailRetryCount , triggerType , triggerTime , i , group .getRegistryList ().size ());
101104 }
102105 } else {
103106 if (shardingParam == null ) {
104107 shardingParam = new int []{0 , 1 };
105108 }
106- processTrigger (group , jobInfo , finalFailRetryCount , triggerType , shardingParam [0 ], shardingParam [1 ]);
109+ processTrigger (group , jobInfo , finalFailRetryCount , triggerType , triggerTime , shardingParam [0 ], shardingParam [1 ]);
107110 }
108111
109112 }
@@ -124,13 +127,15 @@ public void trigger(int jobId,
124127 * @param jobInfo job info
125128 * @param finalFailRetryCount the fail-retry count
126129 * @param triggerType trigger type
130+ * @param triggerTime trigger time
127131 * @param index sharding index
128132 * @param total sharding index
129133 */
130134 private void processTrigger (XxlJobGroup group ,
131135 XxlJobInfo jobInfo ,
132136 int finalFailRetryCount ,
133137 TriggerTypeEnum triggerType ,
138+ Date triggerTime ,
134139 int index ,
135140 int total ){
136141
@@ -143,7 +148,7 @@ private void processTrigger(XxlJobGroup group,
143148 XxlJobLog jobLog = new XxlJobLog ();
144149 jobLog .setJobGroup (jobInfo .getJobGroup ());
145150 jobLog .setJobId (jobInfo .getId ());
146- jobLog .setTriggerTime (new Date () );
151+ jobLog .setTriggerTime (triggerTime );
147152 xxlJobLogMapper .save (jobLog );
148153 logger .debug (">>>>>>>>>>> xxl-job trigger start, jobId:{}" , jobLog .getId ());
149154
@@ -251,22 +256,26 @@ private void processTrigger(XxlJobGroup group,
251256 * @return return
252257 */
253258 private Response <String > doTrigger (TriggerRequest triggerParam , String address ){
254- Response <String > runResult = null ;
255259 try {
260+ // build client
256261 ExecutorBiz executorBiz = XxlJobAdminBootstrap .getExecutorBiz (address );
257- runResult = executorBiz .run (triggerParam );
262+
263+ // invoke
264+ Response <String > runResult = executorBiz .run (triggerParam );
265+
266+ // build result
267+ StringBuffer runResultSB = new StringBuffer (I18nUtil .getString ("jobconf_trigger_run" ) + ":" );
268+ runResultSB .append ("<br>address:" ).append (address );
269+ runResultSB .append ("<br>code:" ).append (runResult .getCode ());
270+ runResultSB .append ("<br>msg:" ).append (runResult .getMsg ());
271+
272+ // return
273+ runResult .setMsg (runResultSB .toString ());
274+ return runResult ;
258275 } catch (Exception e ) {
259276 logger .error (">>>>>>>>>>> xxl-job trigger error, please check if the executor[{}] is running." , address , e );
260- runResult = Response .of (XxlJobContext .HANDLE_CODE_FAIL , ThrowableTool .toString (e ));
277+ return Response .of (XxlJobContext .HANDLE_CODE_FAIL , ThrowableTool .toString (e ));
261278 }
262-
263- StringBuffer runResultSB = new StringBuffer (I18nUtil .getString ("jobconf_trigger_run" ) + ":" );
264- runResultSB .append ("<br>address:" ).append (address );
265- runResultSB .append ("<br>code:" ).append (runResult .getCode ());
266- runResultSB .append ("<br>msg:" ).append (runResult .getMsg ());
267-
268- runResult .setMsg (runResultSB .toString ());
269- return runResult ;
270279 }
271280
272281}
0 commit comments