Skip to content

Commit 07a1ed7

Browse files
walter.tanwalter.tan
authored andcommitted
支持执行器通过XxlJobContext获取job的触发时间
1 parent cc9695b commit 07a1ed7

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

xxl-job-core/src/main/java/com/xxl/job/core/context/XxlJobContext.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public class XxlJobContext {
3131
*/
3232
private final String jobLogFileName;
3333

34+
/**
35+
* log date time
36+
*/
37+
private final long logDateTime;
38+
3439
// ---------------------- for shard ----------------------
3540

3641
/**
@@ -61,10 +66,11 @@ public class XxlJobContext {
6166
private String handleMsg;
6267

6368

64-
public XxlJobContext(long jobId, String jobParam, String jobLogFileName, int shardIndex, int shardTotal) {
69+
public XxlJobContext(long jobId, String jobParam, String jobLogFileName, long logDateTime, int shardIndex, int shardTotal) {
6570
this.jobId = jobId;
6671
this.jobParam = jobParam;
6772
this.jobLogFileName = jobLogFileName;
73+
this.logDateTime = logDateTime;
6874
this.shardIndex = shardIndex;
6975
this.shardTotal = shardTotal;
7076

@@ -83,6 +89,10 @@ public String getJobLogFileName() {
8389
return jobLogFileName;
8490
}
8591

92+
public long getLogDateTime() {
93+
return logDateTime;
94+
}
95+
8696
public int getShardIndex() {
8797
return shardIndex;
8898
}

xxl-job-core/src/main/java/com/xxl/job/core/context/XxlJobHelper.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ public static String getJobLogFileName() {
6464
return xxlJobContext.getJobLogFileName();
6565
}
6666

67+
/**
68+
* current LogDateTime
69+
*
70+
* @return logDateTime
71+
*/
72+
public static long getLogDateTime() {
73+
XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext();
74+
if (xxlJobContext == null) {
75+
return -1;
76+
}
77+
78+
return xxlJobContext.getLogDateTime();
79+
}
80+
6781
// ---------------------- for shard ----------------------
6882

6983
/**

xxl-job-core/src/main/java/com/xxl/job/core/thread/JobThread.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public void run() {
122122
triggerParam.getJobId(),
123123
triggerParam.getExecutorParams(),
124124
logFileName,
125+
triggerParam.getLogDateTime(),
125126
triggerParam.getBroadcastIndex(),
126127
triggerParam.getBroadcastTotal());
127128

xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ private void callbackLog(List<HandleCallbackRequest> callbackParamList, String l
209209
null,
210210
logFileName,
211211
-1,
212+
-1,
212213
-1));
213214
XxlJobHelper.log(logContent);
214215
}

0 commit comments

Comments
 (0)