Skip to content

Commit

Permalink
fix: 运营分析数据最后更新时间不准确 #2904
Browse files Browse the repository at this point in the history
  • Loading branch information
jsonwan committed Apr 19, 2024
1 parent 23b97bc commit 7edb9f0
Showing 1 changed file with 4 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.tencent.bk.job.common.redis.util.HeartBeatRedisLock;
import com.tencent.bk.job.common.redis.util.HeartBeatRedisLockConfig;
import com.tencent.bk.job.common.redis.util.LockResult;
import com.tencent.bk.job.common.redis.util.LockUtils;
import com.tencent.bk.job.common.redis.util.RedisKeyHeartBeatThread;
import com.tencent.bk.job.common.util.ApplicationContextRegister;
import com.tencent.bk.job.common.util.TimeUtil;
Expand Down Expand Up @@ -77,7 +76,6 @@
public class StatisticsTaskScheduler {

private static final String machineIp = IpUtils.getFirstMachineIP();
private static final String REDIS_KEY_STATISTIC_JOB_LOCK = "statistic-job-lock";
private static final String REDIS_KEY_STATISTIC_JOB_RUNNING_MACHINE = "statistic-job-running-machine";
public static final AtomicLong rejectedStatisticsTaskNum = new AtomicLong(0);
private static final String REDIS_KEY_STATISTIC_JOB_INIT_MACHINE = "statistic-job-init-machine";
Expand All @@ -97,18 +95,6 @@ public class StatisticsTaskScheduler {
private ThreadPoolExecutor currentStatisticsTaskExecutor;
private ThreadPoolExecutor pastStatisticsTaskExecutor;

static {
List<String> keyList = Collections.singletonList(REDIS_KEY_STATISTIC_JOB_LOCK);
keyList.forEach(key -> {
try {
//进程重启首先尝试释放上次加上的锁避免死锁
LockUtils.releaseDistributedLock(key, machineIp);
} catch (Throwable t) {
log.info("Redis key:" + key + " does not need to be released, ignore");
}
});
}

private final StatisticConfig statisticConfig;
private final RedisTemplate<String, String> redisTemplate;
private final PastStatisticsMakeupTask pastStatisticsMakeupTask;
Expand Down Expand Up @@ -174,7 +160,7 @@ public boolean configThreads(Integer currentStatisticThreadsNum, Integer pastSta
if (currentStatisticThreadsNum != null && currentStatisticThreadsNum > 0) {
log.info("reconfig currentStatisticsTaskExecutor to {} threads", currentStatisticThreadsNum);
List<Runnable> canceledRunnableList = currentStatisticsTaskExecutor.shutdownNow();
if (canceledRunnableList.size() > 0) {
if (!canceledRunnableList.isEmpty()) {
log.warn("{} threads of canceled", canceledRunnableList.size());
}
currentStatisticsTaskExecutor = new ThreadPoolExecutor(
Expand All @@ -193,7 +179,7 @@ public boolean configThreads(Integer currentStatisticThreadsNum, Integer pastSta
log.info("reconfig pastStatisticsTaskExecutor to {} threads", pastStatisticThreadsNum);
pastStatisticsMakeupTask.setRunFlag(false);
List<Runnable> canceledRunnableList = pastStatisticsTaskExecutor.shutdownNow();
if (canceledRunnableList.size() > 0) {
if (!canceledRunnableList.isEmpty()) {
log.warn("{} threads of pastStatisticsTaskExecutor canceled", canceledRunnableList.size());
}
pastStatisticsTaskExecutor = new ThreadPoolExecutor(
Expand Down Expand Up @@ -265,7 +251,7 @@ public List<String> startTasks(String startDateStr, String endDateStr, List<Stri
}
int count = 0;
int maxPreviousDays = 1000;
while (targetDate.compareTo(startDate) >= 0 && count < maxPreviousDays) {
while (!targetDate.isBefore(startDate) && count < maxPreviousDays) {
startByTaskNameList(taskNameList, targetDate, startedTaskNames);
targetDate = targetDate.minusDays(1);
count += 1;
Expand Down Expand Up @@ -465,7 +451,7 @@ public void schedule() {
futureList.forEach(future -> {
try {
// 最长统计任务耗时约30min
int timeoutMinutes = 50;
int timeoutMinutes = 60;
future.get(timeoutMinutes, TimeUnit.MINUTES);
updateDataUpdateTime(TimeUtil.getCurrentTimeStr());
} catch (InterruptedException | ExecutionException | TimeoutException e) {
Expand Down

0 comments on commit 7edb9f0

Please sign in to comment.