From 2f2809184485e262d5d29e83b4804bdfb8fdb5fa Mon Sep 17 00:00:00 2001 From: Armin Stanitzok <21990230+GODrums@users.noreply.github.com> Date: Fri, 13 Sep 2024 16:16:18 +0200 Subject: [PATCH] Replace `ApplicationRunner` with `EventListener` to fix startup time (#83) --- .../in/www1/hephaestus/codereview/base/Comment.java | 2 -- .../hephaestus/scheduler/GitHubDataSyncScheduler.java | 10 +++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/Comment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/Comment.java index 28de1a79..3070de87 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/Comment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/base/Comment.java @@ -1,11 +1,9 @@ package de.tum.in.www1.hephaestus.codereview.base; import de.tum.in.www1.hephaestus.codereview.user.User; -import jakarta.persistence.Basic; import jakarta.persistence.Column; import jakarta.persistence.FetchType; import jakarta.persistence.JoinColumn; -import jakarta.persistence.Lob; import jakarta.persistence.ManyToOne; import jakarta.persistence.MappedSuperclass; import lombok.AllArgsConstructor; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncScheduler.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncScheduler.java index f16d3db9..4229f91b 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncScheduler.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/scheduler/GitHubDataSyncScheduler.java @@ -3,13 +3,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Component -public class GitHubDataSyncScheduler implements ApplicationRunner { +public class GitHubDataSyncScheduler { private static final Logger logger = LoggerFactory.getLogger(GitHubDataSyncScheduler.class); private final GitHubDataSyncService dataSyncService; @@ -21,8 +21,8 @@ public GitHubDataSyncScheduler(GitHubDataSyncService dataSyncService) { this.dataSyncService = dataSyncService; } - @Override - public void run(ApplicationArguments args) throws Exception { + @EventListener(ApplicationReadyEvent.class) + public void run() { if (runOnStartup) { logger.info("Starting initial GitHub data sync..."); dataSyncService.syncData();