refactor(core): 重构任务上下文日志相关字段及方法

- 将 XxlJobContext 中的日志时间戳和文件名字段重命名为 logDateTime 和 logFileName
- 更新 XxlJobContext 构造函数参数名称以匹配新的字段命名
- 修改 XxlJobHelper 中获取日志信息的方法名称和实现逻辑
- 调整 ScriptJobHandler 和 JobThread 中对日志文件名的调用方式
- 优化 JobThread 中触发队列空值判断条件
- 在 TriggerCallbackThread 初始化 XxlJobContext 时增加缺失的 logId 参数传递
3.3.0-release
xuxueli 7 days ago
parent 2818c28c35
commit 3b7daf6759

@ -27,14 +27,19 @@ public class XxlJobContext {
// ---------------------- for log ---------------------- // ---------------------- for log ----------------------
/** /**
* job log timestamp * log id
*/ */
private final long jobLogTime; private final long logId;
/**
* log timestamp
*/
private final long logDateTime;
/** /**
* job log filename * log filename
*/ */
private final String jobLogFileName; private final String logFileName;
// ---------------------- for shard ---------------------- // ---------------------- for shard ----------------------
@ -66,16 +71,18 @@ public class XxlJobContext {
private String handleMsg; private String handleMsg;
public XxlJobContext(long jobId, public XxlJobContext(long jobId,
String jobParam, String jobParam,
long jobLogTime, long logId,
String jobLogFileName, long logDateTime,
String logFileName,
int shardIndex, int shardIndex,
int shardTotal) { int shardTotal) {
this.jobId = jobId; this.jobId = jobId;
this.jobParam = jobParam; this.jobParam = jobParam;
this.jobLogTime = jobLogTime; this.logId = logId;
this.jobLogFileName = jobLogFileName; this.logDateTime = logDateTime;
this.logFileName = logFileName;
this.shardIndex = shardIndex; this.shardIndex = shardIndex;
this.shardTotal = shardTotal; this.shardTotal = shardTotal;
@ -90,12 +97,16 @@ public class XxlJobContext {
return jobParam; return jobParam;
} }
public String getJobLogFileName() { public long getLogId() {
return jobLogFileName; return logId;
}
public long getLogDateTime() {
return logDateTime;
} }
public long getJobLogTime() { public String getLogFileName() {
return jobLogTime; return logFileName;
} }
public int getShardIndex() { public int getShardIndex() {

@ -18,7 +18,7 @@ import java.util.Date;
*/ */
public class XxlJobHelper { public class XxlJobHelper {
// ---------------------- base info ---------------------- // ---------------------- job info ----------------------
/** /**
* current JobId * current JobId
@ -48,20 +48,34 @@ public class XxlJobHelper {
return xxlJobContext.getJobParam(); return xxlJobContext.getJobParam();
} }
// ---------------------- for log ---------------------- // ---------------------- log info ----------------------
/** /**
* current job log time * current job log time
* *
* @return logDateTime * @return logDateTime
*/ */
public static long getJobLogTime() { public static long getLogId() {
XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext(); XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext();
if (xxlJobContext == null) { if (xxlJobContext == null) {
return -1; return -1;
} }
return xxlJobContext.getJobLogTime(); return xxlJobContext.getLogId();
}
/**
* current job log time
*
* @return logDateTime
*/
public static long getLogDateTime() {
XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext();
if (xxlJobContext == null) {
return -1;
}
return xxlJobContext.getLogDateTime();
} }
/** /**
@ -69,16 +83,16 @@ public class XxlJobHelper {
* *
* @return logFileName * @return logFileName
*/ */
public static String getJobLogFileName() { public static String getLogFileName() {
XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext(); XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext();
if (xxlJobContext == null) { if (xxlJobContext == null) {
return null; return null;
} }
return xxlJobContext.getJobLogFileName(); return xxlJobContext.getLogFileName();
} }
// ---------------------- for shard ---------------------- // ---------------------- shard info ----------------------
/** /**
* current ShardIndex * current ShardIndex
@ -171,7 +185,7 @@ public class XxlJobHelper {
(appendLog != null ? appendLog : ""); (appendLog != null ? appendLog : "");
// appendlog // appendlog
String logFileName = xxlJobContext.getJobLogFileName(); String logFileName = xxlJobContext.getLogFileName();
if (logFileName!=null && !logFileName.trim().isEmpty()) { if (logFileName!=null && !logFileName.trim().isEmpty()) {
XxlJobFileAppender.appendLog(logFileName, formatAppendLog); XxlJobFileAppender.appendLog(logFileName, formatAppendLog);

@ -69,7 +69,7 @@ public class ScriptJobHandler extends IJobHandler {
} }
// log file // log file
String logFileName = XxlJobContext.getXxlJobContext().getJobLogFileName(); String logFileName = XxlJobContext.getXxlJobContext().getLogFileName();
// script params0=param、1=分片序号、2=分片总数 // script params0=param、1=分片序号、2=分片总数
String jobParam = XxlJobHelper.getJobParam(); String jobParam = XxlJobHelper.getJobParam();

@ -115,6 +115,7 @@ public class JobThread extends Thread{
XxlJobContext xxlJobContext = new XxlJobContext( XxlJobContext xxlJobContext = new XxlJobContext(
triggerParam.getJobId(), triggerParam.getJobId(),
triggerParam.getExecutorParams(), triggerParam.getExecutorParams(),
triggerParam.getLogId(),
triggerParam.getLogDateTime(), triggerParam.getLogDateTime(),
logFileName, logFileName,
triggerParam.getBroadcastIndex(), triggerParam.getBroadcastIndex(),
@ -178,7 +179,7 @@ public class JobThread extends Thread{
} else { } else {
if (idleTimes > 30) { if (idleTimes > 30) {
if(triggerQueue.size() == 0) { // avoid concurrent trigger causes jobId-lost if(triggerQueue.isEmpty()) { // avoid concurrent trigger causes jobId-lost
XxlJobExecutor.removeJobThread(jobId, "excutor idle times over limit."); XxlJobExecutor.removeJobThread(jobId, "excutor idle times over limit.");
} }
} }
@ -221,7 +222,7 @@ public class JobThread extends Thread{
} }
// callback trigger request in queue // callback trigger request in queue
while(triggerQueue !=null && triggerQueue.size()>0){ while(triggerQueue !=null && !triggerQueue.isEmpty()){
TriggerRequest triggerParam = triggerQueue.poll(); TriggerRequest triggerParam = triggerQueue.poll();
if (triggerParam!=null) { if (triggerParam!=null) {
// is killed // is killed

@ -208,6 +208,7 @@ public class TriggerCallbackThread {
-1, -1,
null, null,
-1, -1,
-1,
logFileName, logFileName,
-1, -1,
-1)); -1));

Loading…
Cancel
Save