From 8df9755d9f75ed25017abb144fbb43425810919f Mon Sep 17 00:00:00 2001 From: byteblogs168 <598092184@qq.com> Date: Wed, 20 Mar 2024 23:14:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=203.2.0=201.=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E7=B1=BB=EF=BC=8C=E9=81=BF=E5=85=8D=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/init/EasyRetryStartListener.java | 14 ++++++--- .../common/report/AbstractLogReport.java | 15 ++++++++++ .../client/common/report/AsyncReportLog.java | 12 +------- .../retry/client/common/report/LogReport.java | 13 +++++++++ .../retry/server/model/dto/JobLogTaskDTO.java | 29 +++++++++++++++++++ .../retry/server/model/dto/LogTaskDTO.java | 8 ++--- .../server/model/dto/RetryLogTaskDTO.java | 15 ++++++++++ .../server/EasyRetryServerApplication.java | 2 +- .../starter/listener/StartListener.java | 17 +++++++---- .../starter/server/NettyHttpServer.java | 5 ++++ 10 files changed, 104 insertions(+), 26 deletions(-) create mode 100644 easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/AbstractLogReport.java create mode 100644 easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/LogReport.java create mode 100644 easy-retry-common/easy-retry-common-server-api/src/main/java/com/aizuda/easy/retry/server/model/dto/JobLogTaskDTO.java create mode 100644 easy-retry-common/easy-retry-common-server-api/src/main/java/com/aizuda/easy/retry/server/model/dto/RetryLogTaskDTO.java diff --git a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/init/EasyRetryStartListener.java b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/init/EasyRetryStartListener.java index c1af87fe..c0b7071d 100644 --- a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/init/EasyRetryStartListener.java +++ b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/init/EasyRetryStartListener.java @@ -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.util.EasyRetryVersion; import com.aizuda.easy.retry.common.log.EasyRetryLog; +import lombok.RequiredArgsConstructor; import org.slf4j.helpers.MessageFormatter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; @@ -22,19 +23,24 @@ import java.util.List; * @date : 2021-11-19 19:00 */ @Component +@RequiredArgsConstructor public class EasyRetryStartListener implements ApplicationRunner { - - @Autowired - private List lifecycleList; + private final List lifecycleList; + private volatile boolean isStarted = false; @Override 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()); SpringContext.CONTEXT.publishEvent(new EasyRetryStartingEvent()); lifecycleList.forEach(Lifecycle::start); SpringContext.CONTEXT.publishEvent(new EasyRetryStartedEvent()); + isStarted = true; EasyRetryLog.LOCAL.info("Easy-Retry client started successfully v{}", EasyRetryVersion.getVersion()); } diff --git a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/AbstractLogReport.java b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/AbstractLogReport.java new file mode 100644 index 00000000..3e061369 --- /dev/null +++ b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/AbstractLogReport.java @@ -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) { + + } +} diff --git a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/AsyncReportLog.java b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/AsyncReportLog.java index 534f50c4..fbddc21d 100644 --- a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/AsyncReportLog.java +++ b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/AsyncReportLog.java @@ -24,7 +24,7 @@ import java.util.Objects; */ @Component @Slf4j -public class AsyncReportLog implements Lifecycle, Report { +public class AsyncReportLog implements Lifecycle { @Autowired private EasyRetryProperties easyRetryProperties; @@ -85,14 +85,4 @@ public class AsyncReportLog implements Lifecycle, Report { logTaskDTO.setFieldList(logContentDTO.getFieldList()); return logTaskDTO; } - - @Override - public boolean supports(boolean async) { - return false; - } - - @Override - public boolean report(String scene, String targetClassName, Object[] args) { - return false; - } } diff --git a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/LogReport.java b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/LogReport.java new file mode 100644 index 00000000..83fcfc31 --- /dev/null +++ b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/LogReport.java @@ -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); +} diff --git a/easy-retry-common/easy-retry-common-server-api/src/main/java/com/aizuda/easy/retry/server/model/dto/JobLogTaskDTO.java b/easy-retry-common/easy-retry-common-server-api/src/main/java/com/aizuda/easy/retry/server/model/dto/JobLogTaskDTO.java new file mode 100644 index 00000000..48b50a46 --- /dev/null +++ b/easy-retry-common/easy-retry-common-server-api/src/main/java/com/aizuda/easy/retry/server/model/dto/JobLogTaskDTO.java @@ -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; +} diff --git a/easy-retry-common/easy-retry-common-server-api/src/main/java/com/aizuda/easy/retry/server/model/dto/LogTaskDTO.java b/easy-retry-common/easy-retry-common-server-api/src/main/java/com/aizuda/easy/retry/server/model/dto/LogTaskDTO.java index 48ffd58e..a8cf5ab6 100644 --- a/easy-retry-common/easy-retry-common-server-api/src/main/java/com/aizuda/easy/retry/server/model/dto/LogTaskDTO.java +++ b/easy-retry-common/easy-retry-common-server-api/src/main/java/com/aizuda/easy/retry/server/model/dto/LogTaskDTO.java @@ -16,11 +16,6 @@ import java.util.List; @Data public class LogTaskDTO implements Serializable { - /** - * 主键 - */ - private Long id; - /** * 命名空间 */ @@ -34,16 +29,19 @@ public class LogTaskDTO implements Serializable { /** * 任务信息id */ + @Deprecated private Long jobId; /** * 任务实例id */ + @Deprecated private Long taskBatchId; /** * 调度任务id */ + @Deprecated private Long taskId; /** diff --git a/easy-retry-common/easy-retry-common-server-api/src/main/java/com/aizuda/easy/retry/server/model/dto/RetryLogTaskDTO.java b/easy-retry-common/easy-retry-common-server-api/src/main/java/com/aizuda/easy/retry/server/model/dto/RetryLogTaskDTO.java new file mode 100644 index 00000000..a6d58d50 --- /dev/null +++ b/easy-retry-common/easy-retry-common-server-api/src/main/java/com/aizuda/easy/retry/server/model/dto/RetryLogTaskDTO.java @@ -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 { + +} diff --git a/easy-retry-server/easy-retry-server-starter/src/main/java/com/aizuda/easy/retry/server/EasyRetryServerApplication.java b/easy-retry-server/easy-retry-server-starter/src/main/java/com/aizuda/easy/retry/server/EasyRetryServerApplication.java index 2e811c3f..00dfa696 100644 --- a/easy-retry-server/easy-retry-server-starter/src/main/java/com/aizuda/easy/retry/server/EasyRetryServerApplication.java +++ b/easy-retry-server/easy-retry-server-starter/src/main/java/com/aizuda/easy/retry/server/EasyRetryServerApplication.java @@ -27,7 +27,7 @@ public class EasyRetryServerApplication { return args -> { // 最长自旋10秒,保证nettyHttpServer启动完成 int waitCount = 0; - while (!nettyHttpServer.isStarted() || waitCount > 100) { + while (!nettyHttpServer.isStarted() && waitCount < 100) { log.info("--------> easy-retry netty server is staring...."); TimeUnit.MILLISECONDS.sleep(100); waitCount++; diff --git a/easy-retry-server/easy-retry-server-starter/src/main/java/com/aizuda/easy/retry/server/starter/listener/StartListener.java b/easy-retry-server/easy-retry-server-starter/src/main/java/com/aizuda/easy/retry/server/starter/listener/StartListener.java index 2fc513df..e27eb58e 100644 --- a/easy-retry-server/easy-retry-server-starter/src/main/java/com/aizuda/easy/retry/server/starter/listener/StartListener.java +++ b/easy-retry-server/easy-retry-server-starter/src/main/java/com/aizuda/easy/retry/server/starter/listener/StartListener.java @@ -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.core.util.EasyRetryVersion; import com.aizuda.easy.retry.server.common.Lifecycle; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.slf4j.helpers.MessageFormatter; import org.springframework.beans.factory.annotation.Autowired; @@ -20,17 +21,23 @@ import java.util.List; * @date : 2021-11-19 19:00 */ @Component +@RequiredArgsConstructor @Slf4j public class StartListener implements ApplicationListener { - - @Autowired - private List lifecycleList; + private final List lifecycleList; + private volatile boolean isStarted = false; @Override 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()); - 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); - EasyRetryLog.LOCAL.info("easy-retry-server v{} start completed", EasyRetryVersion.getVersion()); + EasyRetryLog.LOCAL.info("Easy-Retry server started successfully v{}", EasyRetryVersion.getVersion()); + isStarted = true; } } diff --git a/easy-retry-server/easy-retry-server-starter/src/main/java/com/aizuda/easy/retry/server/starter/server/NettyHttpServer.java b/easy-retry-server/easy-retry-server-starter/src/main/java/com/aizuda/easy/retry/server/starter/server/NettyHttpServer.java index 3ea1ff27..6f52b774 100644 --- a/easy-retry-server/easy-retry-server-starter/src/main/java/com/aizuda/easy/retry/server/starter/server/NettyHttpServer.java +++ b/easy-retry-server/easy-retry-server-starter/src/main/java/com/aizuda/easy/retry/server/starter/server/NettyHttpServer.java @@ -37,6 +37,11 @@ public class NettyHttpServer implements Runnable, Lifecycle { @Override public void run() { + // 防止重复启动 + if (started) { + return; + } + EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup();