feat: 3.2.0

1. 优化启动类,避免重复加载
This commit is contained in:
byteblogs168 2024-03-20 23:30:28 +08:00
parent 8df9755d9f
commit c820fcda3f
3 changed files with 102 additions and 1 deletions

View File

@ -1,15 +1,54 @@
package com.aizuda.easy.retry.client.common.report;
import com.aizuda.easy.retry.client.common.Lifecycle;
import com.aizuda.easy.retry.client.common.config.EasyRetryProperties;
import com.aizuda.easy.retry.client.common.window.SlidingWindow;
import com.aizuda.easy.retry.common.log.EasyRetryLog;
import com.aizuda.easy.retry.common.log.dto.LogContentDTO;
import com.aizuda.easy.retry.server.model.dto.LogTaskDTO;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Objects;
/**
* @author xiaowoniu
* @date 2024-03-20 22:56:53
* @since 3.2.0
*/
public abstract class AbstractLogReport implements LogReport{
public abstract class AbstractLogReport implements Lifecycle, LogReport {
@Autowired
private EasyRetryProperties easyRetryProperties;
private SlidingWindow<? super LogTaskDTO> slidingWindow;
@Override
public void report(LogContentDTO logContentDTO) {
slidingWindow.add(buildLogTaskDTO(logContentDTO));
}
protected abstract LogTaskDTO buildLogTaskDTO(LogContentDTO logContentDTO);
@Override
public void start() {
EasyRetryProperties.LogSlidingWindowConfig logSlidingWindow = easyRetryProperties.getLogSlidingWindow();
slidingWindow = SlidingWindow
.Builder
.<LogTaskDTO>newBuilder()
.withTotalThreshold(logSlidingWindow.getTotalThreshold())
.withWindowTotalThreshold(logSlidingWindow.getWindowTotalThreshold())
.withDuration(logSlidingWindow.getDuration(), logSlidingWindow.getChronoUnit())
.withListener(new ReportLogListener())
.build();
slidingWindow.start();
}
@Override
public void close() {
EasyRetryLog.LOCAL.info("AsyncReport Log about to shutdown");
if (Objects.nonNull(slidingWindow)) {
slidingWindow.end();
}
EasyRetryLog.LOCAL.info("AsyncReport Log has been shutdown");
}
}

View File

@ -0,0 +1,31 @@
package com.aizuda.easy.retry.client.core.log;
import com.aizuda.easy.retry.client.common.report.AbstractLogReport;
import com.aizuda.easy.retry.client.common.util.ThreadLocalLogUtil;
import com.aizuda.easy.retry.common.core.model.JobContext;
import com.aizuda.easy.retry.common.log.dto.LogContentDTO;
import com.aizuda.easy.retry.server.model.dto.LogTaskDTO;
import org.springframework.stereotype.Component;
/**
* @author xiaowoniu
* @date 2024-03-20 23:25:24
* @since 3.2.0
*/
//@Component
public class RetryLogReport extends AbstractLogReport {
@Override
protected LogTaskDTO buildLogTaskDTO(LogContentDTO logContentDTO) {
// JobContext context = ThreadLocalLogUtil.getContext();
LogTaskDTO logTaskDTO = new LogTaskDTO();
// logTaskDTO.setJobId(context.getJobId());
// logTaskDTO.setTaskId(context.getTaskId());
// logTaskDTO.setTaskBatchId(context.getTaskBatchId());
// logTaskDTO.setRealTime(logContentDTO.getTimeStamp());
// logTaskDTO.setNamespaceId(context.getNamespaceId());
// logTaskDTO.setGroupName(context.getGroupName());
logTaskDTO.setFieldList(logContentDTO.getFieldList());
return logTaskDTO;
}
}

View File

@ -0,0 +1,31 @@
package com.aizuda.easy.retry.client.job.core.log;
import com.aizuda.easy.retry.client.common.report.AbstractLogReport;
import com.aizuda.easy.retry.client.common.util.ThreadLocalLogUtil;
import com.aizuda.easy.retry.common.core.model.JobContext;
import com.aizuda.easy.retry.common.log.dto.LogContentDTO;
import com.aizuda.easy.retry.server.model.dto.LogTaskDTO;
import org.springframework.stereotype.Component;
/**
* @author xiaowoniu
* @date 2024-03-20 23:25:24
* @since 3.2.0
*/
//@Component
public class JobLogReport extends AbstractLogReport {
@Override
protected LogTaskDTO buildLogTaskDTO(LogContentDTO logContentDTO) {
JobContext context = ThreadLocalLogUtil.getContext();
LogTaskDTO logTaskDTO = new LogTaskDTO();
logTaskDTO.setJobId(context.getJobId());
logTaskDTO.setTaskId(context.getTaskId());
logTaskDTO.setTaskBatchId(context.getTaskBatchId());
logTaskDTO.setRealTime(logContentDTO.getTimeStamp());
logTaskDTO.setNamespaceId(context.getNamespaceId());
logTaskDTO.setGroupName(context.getGroupName());
logTaskDTO.setFieldList(logContentDTO.getFieldList());
return logTaskDTO;
}
}