feat: 3.2.0

1. 优化启动类,避免重复加载
This commit is contained in:
byteblogs168 2024-03-20 23:14:16 +08:00
parent dcb2a008d6
commit 8df9755d9f
10 changed files with 104 additions and 26 deletions

View File

@ -7,6 +7,7 @@ import com.aizuda.easy.retry.common.core.constant.SystemConstants;
import com.aizuda.easy.retry.common.core.context.SpringContext; import com.aizuda.easy.retry.common.core.context.SpringContext;
import com.aizuda.easy.retry.common.core.util.EasyRetryVersion; import com.aizuda.easy.retry.common.core.util.EasyRetryVersion;
import com.aizuda.easy.retry.common.log.EasyRetryLog; import com.aizuda.easy.retry.common.log.EasyRetryLog;
import lombok.RequiredArgsConstructor;
import org.slf4j.helpers.MessageFormatter; import org.slf4j.helpers.MessageFormatter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationArguments;
@ -22,19 +23,24 @@ import java.util.List;
* @date : 2021-11-19 19:00 * @date : 2021-11-19 19:00
*/ */
@Component @Component
@RequiredArgsConstructor
public class EasyRetryStartListener implements ApplicationRunner { public class EasyRetryStartListener implements ApplicationRunner {
private final List<Lifecycle> lifecycleList;
@Autowired private volatile boolean isStarted = false;
private List<Lifecycle> lifecycleList;
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
System.out.println(MessageFormatter.format(SystemConstants.LOGO, EasyRetryVersion.getVersion()).getMessage()); if (isStarted) {
EasyRetryLog.LOCAL.info("Easy-Retry client already started v{}", EasyRetryVersion.getVersion());
return;
}
System.out.println(MessageFormatter.format(SystemConstants.LOGO, EasyRetryVersion.getVersion()).getMessage());
EasyRetryLog.LOCAL.info("Easy-Retry client is preparing to start... v{}", EasyRetryVersion.getVersion()); EasyRetryLog.LOCAL.info("Easy-Retry client is preparing to start... v{}", EasyRetryVersion.getVersion());
SpringContext.CONTEXT.publishEvent(new EasyRetryStartingEvent()); SpringContext.CONTEXT.publishEvent(new EasyRetryStartingEvent());
lifecycleList.forEach(Lifecycle::start); lifecycleList.forEach(Lifecycle::start);
SpringContext.CONTEXT.publishEvent(new EasyRetryStartedEvent()); SpringContext.CONTEXT.publishEvent(new EasyRetryStartedEvent());
isStarted = true;
EasyRetryLog.LOCAL.info("Easy-Retry client started successfully v{}", EasyRetryVersion.getVersion()); EasyRetryLog.LOCAL.info("Easy-Retry client started successfully v{}", EasyRetryVersion.getVersion());
} }

View File

@ -0,0 +1,15 @@
package com.aizuda.easy.retry.client.common.report;
import com.aizuda.easy.retry.common.log.dto.LogContentDTO;
/**
* @author xiaowoniu
* @date 2024-03-20 22:56:53
* @since 3.2.0
*/
public abstract class AbstractLogReport implements LogReport{
@Override
public void report(LogContentDTO logContentDTO) {
}
}

View File

@ -24,7 +24,7 @@ import java.util.Objects;
*/ */
@Component @Component
@Slf4j @Slf4j
public class AsyncReportLog implements Lifecycle, Report { public class AsyncReportLog implements Lifecycle {
@Autowired @Autowired
private EasyRetryProperties easyRetryProperties; private EasyRetryProperties easyRetryProperties;
@ -85,14 +85,4 @@ public class AsyncReportLog implements Lifecycle, Report {
logTaskDTO.setFieldList(logContentDTO.getFieldList()); logTaskDTO.setFieldList(logContentDTO.getFieldList());
return logTaskDTO; return logTaskDTO;
} }
@Override
public boolean supports(boolean async) {
return false;
}
@Override
public boolean report(String scene, String targetClassName, Object[] args) {
return false;
}
} }

View File

@ -0,0 +1,13 @@
package com.aizuda.easy.retry.client.common.report;
import com.aizuda.easy.retry.common.log.dto.LogContentDTO;
/**
* @author xiaowoniu
* @date 2024-03-20 22:56:53
* @since 3.2.0
*/
public interface LogReport {
void report(LogContentDTO logContentDTO);
}

View File

@ -0,0 +1,29 @@
package com.aizuda.easy.retry.server.model.dto;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author xiaowoniu
* @date 2024-03-20 23:08:26
* @since 3.2.0
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class JobLogTaskDTO extends LogTaskDTO {
/**
* 任务信息id
*/
private Long jobId;
/**
* 任务实例id
*/
private Long taskBatchId;
/**
* 调度任务id
*/
private Long taskId;
}

View File

@ -16,11 +16,6 @@ import java.util.List;
@Data @Data
public class LogTaskDTO implements Serializable { public class LogTaskDTO implements Serializable {
/**
* 主键
*/
private Long id;
/** /**
* 命名空间 * 命名空间
*/ */
@ -34,16 +29,19 @@ public class LogTaskDTO implements Serializable {
/** /**
* 任务信息id * 任务信息id
*/ */
@Deprecated
private Long jobId; private Long jobId;
/** /**
* 任务实例id * 任务实例id
*/ */
@Deprecated
private Long taskBatchId; private Long taskBatchId;
/** /**
* 调度任务id * 调度任务id
*/ */
@Deprecated
private Long taskId; private Long taskId;
/** /**

View File

@ -0,0 +1,15 @@
package com.aizuda.easy.retry.server.model.dto;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author xiaowoniu
* @date 2024-03-20 23:08:26
* @since 3.2.0
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class RetryLogTaskDTO extends LogTaskDTO {
}

View File

@ -27,7 +27,7 @@ public class EasyRetryServerApplication {
return args -> { return args -> {
// 最长自旋10秒保证nettyHttpServer启动完成 // 最长自旋10秒保证nettyHttpServer启动完成
int waitCount = 0; int waitCount = 0;
while (!nettyHttpServer.isStarted() || waitCount > 100) { while (!nettyHttpServer.isStarted() && waitCount < 100) {
log.info("--------> easy-retry netty server is staring...."); log.info("--------> easy-retry netty server is staring....");
TimeUnit.MILLISECONDS.sleep(100); TimeUnit.MILLISECONDS.sleep(100);
waitCount++; waitCount++;

View File

@ -4,6 +4,7 @@ import com.aizuda.easy.retry.common.core.constant.SystemConstants;
import com.aizuda.easy.retry.common.log.EasyRetryLog; import com.aizuda.easy.retry.common.log.EasyRetryLog;
import com.aizuda.easy.retry.common.core.util.EasyRetryVersion; import com.aizuda.easy.retry.common.core.util.EasyRetryVersion;
import com.aizuda.easy.retry.server.common.Lifecycle; import com.aizuda.easy.retry.server.common.Lifecycle;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.slf4j.helpers.MessageFormatter; import org.slf4j.helpers.MessageFormatter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -20,17 +21,23 @@ import java.util.List;
* @date : 2021-11-19 19:00 * @date : 2021-11-19 19:00
*/ */
@Component @Component
@RequiredArgsConstructor
@Slf4j @Slf4j
public class StartListener implements ApplicationListener<ContextRefreshedEvent> { public class StartListener implements ApplicationListener<ContextRefreshedEvent> {
private final List<Lifecycle> lifecycleList;
@Autowired private volatile boolean isStarted = false;
private List<Lifecycle> lifecycleList;
@Override @Override
public void onApplicationEvent(ContextRefreshedEvent event) { public void onApplicationEvent(ContextRefreshedEvent event) {
if (isStarted) {
EasyRetryLog.LOCAL.info("Easy-Retry server already started v{}", EasyRetryVersion.getVersion());
return;
}
System.out.println(MessageFormatter.format(SystemConstants.LOGO, EasyRetryVersion.getVersion()).getMessage()); System.out.println(MessageFormatter.format(SystemConstants.LOGO, EasyRetryVersion.getVersion()).getMessage());
EasyRetryLog.LOCAL.info("easy-retry-server v{} starting...", EasyRetryVersion.getVersion()); EasyRetryLog.LOCAL.info("Easy-Retry server is preparing to start... v{}", EasyRetryVersion.getVersion());
lifecycleList.forEach(Lifecycle::start); lifecycleList.forEach(Lifecycle::start);
EasyRetryLog.LOCAL.info("easy-retry-server v{} start completed", EasyRetryVersion.getVersion()); EasyRetryLog.LOCAL.info("Easy-Retry server started successfully v{}", EasyRetryVersion.getVersion());
isStarted = true;
} }
} }

View File

@ -37,6 +37,11 @@ public class NettyHttpServer implements Runnable, Lifecycle {
@Override @Override
public void run() { public void run() {
// 防止重复启动
if (started) {
return;
}
EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup();