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 ----------------------
/**
* 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 ----------------------
@ -66,16 +71,18 @@ public class XxlJobContext {
private String handleMsg;
public XxlJobContext(long jobId,
public XxlJobContext(long jobId,
String jobParam,
long jobLogTime,
String jobLogFileName,
long logId,
long logDateTime,
String logFileName,
int shardIndex,
int shardTotal) {
this.jobId = jobId;
this.jobParam = jobParam;
this.jobLogTime = jobLogTime;
this.jobLogFileName = jobLogFileName;
this.logId = logId;
this.logDateTime = logDateTime;
this.logFileName = logFileName;
this.shardIndex = shardIndex;
this.shardTotal = shardTotal;
@ -90,12 +97,16 @@ public class XxlJobContext {
return jobParam;
}
public String getJobLogFileName() {
return jobLogFileName;
public long getLogId() {
return logId;
}
public long getLogDateTime() {
return logDateTime;
}
public long getJobLogTime() {
return jobLogTime;
public String getLogFileName() {
return logFileName;
}
public int getShardIndex() {

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

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

@ -115,6 +115,7 @@ public class JobThread extends Thread{
XxlJobContext xxlJobContext = new XxlJobContext(
triggerParam.getJobId(),
triggerParam.getExecutorParams(),
triggerParam.getLogId(),
triggerParam.getLogDateTime(),
logFileName,
triggerParam.getBroadcastIndex(),
@ -178,7 +179,7 @@ public class JobThread extends Thread{
} else {
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.");
}
}
@ -221,7 +222,7 @@ public class JobThread extends Thread{
}
// callback trigger request in queue
while(triggerQueue !=null && triggerQueue.size()>0){
while(triggerQueue !=null && !triggerQueue.isEmpty()){
TriggerRequest triggerParam = triggerQueue.poll();
if (triggerParam!=null) {
// is killed

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

Loading…
Cancel
Save