Skip to content

feat 可配置化预读时间 #3567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javax.annotation.Resource;
import javax.sql.DataSource;
import java.util.Arrays;
import java.util.Optional;

/**
* xxl-job config
Expand Down Expand Up @@ -67,6 +68,9 @@ public void destroy() throws Exception {
@Value("${xxl.job.logretentiondays}")
private int logretentiondays;

@Value("${xxl.job.pre-read-ms}")
private long preReadMs;

// dao, service

@Resource
Expand Down Expand Up @@ -123,6 +127,10 @@ public int getLogretentiondays() {
return logretentiondays;
}

public long getPreReadMs() {
return Optional.ofNullable(preReadMs).orElse(5000l);
}

public XxlJobLogDao getXxlJobLogDao() {
return xxlJobLogDao;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public static JobScheduleHelper getInstance(){
return instance;
}

public static final long PRE_READ_MS = 5000; // pre read

private Thread scheduleThread;
private Thread ringThread;
private volatile boolean scheduleThreadToStop = false;
Expand Down Expand Up @@ -77,13 +75,13 @@ public void run() {

// 1、pre read
long nowTime = System.currentTimeMillis();
List<XxlJobInfo> scheduleList = XxlJobAdminConfig.getAdminConfig().getXxlJobInfoDao().scheduleJobQuery(nowTime + PRE_READ_MS, preReadCount);
List<XxlJobInfo> scheduleList = XxlJobAdminConfig.getAdminConfig().getXxlJobInfoDao().scheduleJobQuery(nowTime + XxlJobAdminConfig.getAdminConfig().getPreReadMs(), preReadCount);
if (scheduleList!=null && scheduleList.size()>0) {
// 2、push time-ring
for (XxlJobInfo jobInfo: scheduleList) {

// time-ring jump
if (nowTime > jobInfo.getTriggerNextTime() + PRE_READ_MS) {
if (nowTime > jobInfo.getTriggerNextTime() + XxlJobAdminConfig.getAdminConfig().getPreReadMs()) {
// 2.1、trigger-expire > 5s:pass && make next-trigger-time
logger.warn(">>>>>>>>>>> xxl-job, schedule misfire, jobId = " + jobInfo.getId());

Expand All @@ -109,7 +107,7 @@ public void run() {
refreshNextValidTime(jobInfo, new Date());

// next-trigger-time in 5s, pre-read again
if (jobInfo.getTriggerStatus()==1 && nowTime + PRE_READ_MS > jobInfo.getTriggerNextTime()) {
if (jobInfo.getTriggerStatus()==1 && nowTime + XxlJobAdminConfig.getAdminConfig().getPreReadMs() > jobInfo.getTriggerNextTime()) {

// 1、make ring second
int ringSecond = (int)((jobInfo.getTriggerNextTime()/1000)%60);
Expand Down Expand Up @@ -199,7 +197,7 @@ public void run() {
if (cost < 1000) { // scan-overtime, not wait
try {
// pre-read period: success > scan each second; fail > skip this period;
TimeUnit.MILLISECONDS.sleep((preReadSuc?1000:PRE_READ_MS) - System.currentTimeMillis()%1000);
TimeUnit.MILLISECONDS.sleep((preReadSuc?1000:XxlJobAdminConfig.getAdminConfig().getPreReadMs()) - System.currentTimeMillis()%1000);
} catch (InterruptedException e) {
if (!scheduleThreadToStop) {
logger.error(e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.xxl.job.admin.service.impl;

import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
import com.xxl.job.admin.core.cron.CronExpression;
import com.xxl.job.admin.core.model.XxlJobGroup;
import com.xxl.job.admin.core.model.XxlJobInfo;
Expand Down Expand Up @@ -264,7 +265,7 @@ public ReturnT<String> update(XxlJobInfo jobInfo, XxlJobUser loginUser) {
boolean scheduleDataNotChanged = jobInfo.getScheduleType().equals(exists_jobInfo.getScheduleType()) && jobInfo.getScheduleConf().equals(exists_jobInfo.getScheduleConf());
if (exists_jobInfo.getTriggerStatus() == 1 && !scheduleDataNotChanged) {
try {
Date nextValidTime = JobScheduleHelper.generateNextValidTime(jobInfo, new Date(System.currentTimeMillis() + JobScheduleHelper.PRE_READ_MS));
Date nextValidTime = JobScheduleHelper.generateNextValidTime(jobInfo, new Date(System.currentTimeMillis() + XxlJobAdminConfig.getAdminConfig().getPreReadMs()));
if (nextValidTime == null) {
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) );
}
Expand Down Expand Up @@ -324,7 +325,7 @@ public ReturnT<String> start(int id) {
// next trigger time (5s后生效,避开预读周期)
long nextTriggerTime = 0;
try {
Date nextValidTime = JobScheduleHelper.generateNextValidTime(xxlJobInfo, new Date(System.currentTimeMillis() + JobScheduleHelper.PRE_READ_MS));
Date nextValidTime = JobScheduleHelper.generateNextValidTime(xxlJobInfo, new Date(System.currentTimeMillis() + XxlJobAdminConfig.getAdminConfig().getPreReadMs()));
if (nextValidTime == null) {
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("schedule_type")+I18nUtil.getString("system_unvalid")) );
}
Expand Down
3 changes: 3 additions & 0 deletions xxl-job-admin/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ xxl.job.triggerpool.slow.max=100

### xxl-job, log retention days
xxl.job.logretentiondays=30

### xxl-job, other
xxl.job.pre-read-ms=5000