From f626a8fafd60ac46764079ece04e6d568119d468 Mon Sep 17 00:00:00 2001 From: jemin Date: Fri, 26 Apr 2024 10:17:42 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20dev=20=ED=99=98=EA=B2=BD=20=EB=B3=80?= =?UTF-8?q?=EC=88=98=20=ED=8C=8C=EC=9D=BC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 8 +++---- .github/workflows/deploy-dev.yml | 11 ++++----- appspec.dev.yml | 6 ++--- build.gradle | 6 ++--- scripts/dev/health_check.sh | 18 +++++++------- scripts/dev/run_new_was.sh | 24 +++++++++---------- .../backend/global/config/RedisConfig.java | 15 +----------- .../global/config/SchedulerConfig.java | 7 ------ .../com/backend/global/entity/BaseEntity.java | 1 - .../global/scheduler/SchedulerService.java | 12 +--------- src/main/resources/config | 2 +- 11 files changed, 38 insertions(+), 72 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c944704..115de0e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,7 @@ name: build/test -on: # when the workflows should be triggered ? - pull_request: # Starting Build when pull request is created. +on: + pull_request: branches: [ "main", "dev"] permissions: @@ -9,7 +9,7 @@ permissions: checks: write issues: write -jobs: # defining jobs, executed in this workflows +jobs: build: runs-on: ubuntu-latest services: @@ -19,7 +19,7 @@ jobs: # defining jobs, executed in this workflows - 6379:6379 steps: - name: Checkout repository - uses: actions/checkout@v3 # clone repository + uses: actions/checkout@v3 with: token: ${{ secrets.ACTION_TOKEN }} submodules: true diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index 1e3f224..0b6682c 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v3 # clone repository + uses: actions/checkout@v3 with: token: ${{ secrets.ACTION_TOKEN }} submodules: true @@ -17,7 +17,6 @@ jobs: - name: Update submodules run: git submodule update --remote - # Caching Gradle - name: Cache Gradle uses: actions/cache@v3 with: @@ -56,12 +55,12 @@ jobs: run: | aws s3 cp \ --region ap-northeast-2 \ - ./$GITHUB_SHA.zip s3://dnd-9th-1-s3 + ./$GITHUB_SHA.zip s3://milestone-deploy-dev - name: Request to CodeDeploy run: | aws deploy create-deployment \ - --application-name dnd-9th-1-codedeploy \ + --application-name milestone-deploy-dev \ --deployment-config-name CodeDeployDefault.AllAtOnce \ - --deployment-group-name milestone-prod-deployment-group \ - --s3-location bucket=dnd-9th-1-s3,bundleType=zip,key=$GITHUB_SHA.zip \ No newline at end of file + --deployment-group-name milestone-deploy-group-dev \ + --s3-location bucket=milestone-deploy-dev,bundleType=zip,key=$GITHUB_SHA.zip \ No newline at end of file diff --git a/appspec.dev.yml b/appspec.dev.yml index 323f284..3c56f23 100644 --- a/appspec.dev.yml +++ b/appspec.dev.yml @@ -22,6 +22,6 @@ hooks: - location: scripts/dev/health_check.sh timeout: 180 runas: ubuntu - - location: scripts/dev/switch.sh - timeout: 180 - runas: ubuntu \ No newline at end of file +# - location: scripts/dev/switch.sh +# timeout: 180 +# runas: ubuntu \ No newline at end of file diff --git a/build.gradle b/build.gradle index b7560e4..966b06f 100644 --- a/build.gradle +++ b/build.gradle @@ -24,6 +24,7 @@ dependencies { // jpa implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + // security implementation 'org.springframework.boot:spring-boot-starter-security' @@ -32,7 +33,7 @@ dependencies { annotationProcessor 'org.projectlombok:lombok' // database - implementation 'org.mariadb.jdbc:mariadb-java-client:3.1.4' + runtimeOnly 'com.mysql:mysql-connector-j' runtimeOnly 'com.h2database:h2' implementation 'org.springframework.boot:spring-boot-starter-data-redis' @@ -46,9 +47,6 @@ dependencies { testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' - implementation 'net.javacrumbs.shedlock:shedlock-spring:5.1.0' - implementation 'net.javacrumbs.shedlock:shedlock-provider-redis-spring:5.1.0' - implementation 'org.springframework.boot:spring-boot-starter-webflux' implementation 'org.springframework.boot:spring-boot-starter' implementation 'org.springframework.boot:spring-boot-starter-web' diff --git a/scripts/dev/health_check.sh b/scripts/dev/health_check.sh index 954153b..45a1744 100644 --- a/scripts/dev/health_check.sh +++ b/scripts/dev/health_check.sh @@ -2,17 +2,17 @@ # Crawl current connected port of WAS CURRENT_PORT=$(cat /home/ubuntu/dev_url.inc | grep -Po '[0-9]+' | tail -1) -TARGET_PORT=0 +TARGET_PORT=8080 # Toggle port Number -if [ ${CURRENT_PORT} -eq 8083 ]; then - TARGET_PORT=8084 -elif [ ${CURRENT_PORT} -eq 8084 ]; then - TARGET_PORT=8083 -else - echo "> No WAS is connected to nginx" - exit 1 -fi +#if [ ${CURRENT_PORT} -eq 8083 ]; then +# TARGET_PORT=8084 +#elif [ ${CURRENT_PORT} -eq 8084 ]; then +# TARGET_PORT=8083 +#else +# echo "> No WAS is connected to nginx" +# exit 1 +#fi echo "> Start health check of WAS at 'http://127.0.0.1:${TARGET_PORT}' ..." diff --git a/scripts/dev/run_new_was.sh b/scripts/dev/run_new_was.sh index d58b881..73973bd 100644 --- a/scripts/dev/run_new_was.sh +++ b/scripts/dev/run_new_was.sh @@ -5,22 +5,22 @@ echo "> Start run_new_was.sh" # Parse port number from 'dev_url.inc' CURRENT_PORT=$(cat /home/ubuntu/dev_url.inc | grep -Po '[0-9]+' | tail -1) CURRENT_PROFILE=dev -TARGET_PORT=0 +TARGET_PORT=8080 -echo "> Current port of running WAS is ${CURRENT_PORT}." +#echo "> Current port of running WAS is ${CURRENT_PORT}." -# Find target port to switch -if [ ${CURRENT_PORT} -eq 8083 ]; then - TARGET_PORT=8084 -elif [ ${CURRENT_PORT} -eq 8084 ]; then - TARGET_PORT=8083 -else - echo "> No WAS is connected to nginx" -fi +## Find target port to switch +#if [ ${CURRENT_PORT} -eq 8083 ]; then +# TARGET_PORT=8084 +#elif [ ${CURRENT_PORT} -eq 8084 ]; then +# TARGET_PORT=8083 +#else +# echo "> No WAS is connected to nginx" +#fi # query pid using the TCP protocol and using the port 'TARGET_PORT' -echo "> Kill WAS running at ${TARGET_PORT}." -sudo kill $(sudo lsof -t -i:${TARGET_PORT}) +#echo "> Kill WAS running at ${TARGET_PORT}." +#sudo kill $(sudo lsof -t -i:${TARGET_PORT}) # run jar file in background nohup sudo java -jar -Duser.timezone="Asia/Seoul" -Dspring.profiles.active=${CURRENT_PROFILE} -Dserver.port=${TARGET_PORT} /home/ubuntu/dev/build/libs/backend-0.0.1-SNAPSHOT.jar > /home/ubuntu/dev/nohup.out 2>&1 & diff --git a/src/main/java/com/backend/global/config/RedisConfig.java b/src/main/java/com/backend/global/config/RedisConfig.java index 3b93ee1..08332ab 100644 --- a/src/main/java/com/backend/global/config/RedisConfig.java +++ b/src/main/java/com/backend/global/config/RedisConfig.java @@ -1,18 +1,13 @@ package com.backend.auth.config; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.Environment; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisStandaloneConfiguration; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; -import net.javacrumbs.shedlock.core.LockProvider; -import net.javacrumbs.shedlock.provider.redis.spring.RedisLockProvider; - @Configuration @EnableRedisRepositories public class RedisConfig { @@ -23,20 +18,12 @@ public class RedisConfig { @Value("${spring.data.redis.port}") private int port; - @Autowired - Environment env; - @Bean - public RedisConnectionFactory connectionFactory(){ + public RedisConnectionFactory connectionFactory() { RedisStandaloneConfiguration redisConfiguration = new RedisStandaloneConfiguration(); redisConfiguration.setHostName(host); redisConfiguration.setPort(port); return new LettuceConnectionFactory(redisConfiguration); } - @Bean - public LockProvider lockProvider(RedisConnectionFactory connectionFactory) { - String lockEnv = env.getProperty("spring.profiles.active"); - return new RedisLockProvider(connectionFactory, lockEnv); - } } \ No newline at end of file diff --git a/src/main/java/com/backend/global/config/SchedulerConfig.java b/src/main/java/com/backend/global/config/SchedulerConfig.java index 7dac795..b85d1fd 100644 --- a/src/main/java/com/backend/global/config/SchedulerConfig.java +++ b/src/main/java/com/backend/global/config/SchedulerConfig.java @@ -6,22 +6,15 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.scheduling.config.ScheduledTaskRegistrar; -import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock; @Configuration @EnableScheduling -@EnableSchedulerLock(defaultLockAtLeastFor = "5s", defaultLockAtMostFor = "5s") public class SchedulerConfig implements SchedulingConfigurer { private static final String SCHEDULER_THREAD_POOL_NAME = "scheduler thread pool"; private static final String THREAD_NAME_PREFIX = "scheduler-thread-"; private static final int POOL_SIZE = 3; - /* - 쓰레드풀 사이즈를 선정할때는 필요 이상으로 크게 할당하는걸 경계해야 합니다. - 서비스에 쓰레드 개수가 늘어나는건 쓰레드 간 경합을 증가시켜서 컨텍스트 스위칭 비용을 증가시킵니다. - 따라서 현재 서비스에 스케쥴러가 2개만 존재하고 스케쥴링 간격이 긴 만큼 여유분 1개를 추가해서 총 3개의 쓰레드를 할당했습니다. - */ @Override public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); diff --git a/src/main/java/com/backend/global/entity/BaseEntity.java b/src/main/java/com/backend/global/entity/BaseEntity.java index 04a91dd..8efbf78 100644 --- a/src/main/java/com/backend/global/entity/BaseEntity.java +++ b/src/main/java/com/backend/global/entity/BaseEntity.java @@ -3,7 +3,6 @@ import jakarta.persistence.Column; import jakarta.persistence.EntityListeners; import jakarta.persistence.MappedSuperclass; -import org.mariadb.jdbc.plugin.codec.LocalDateTimeCodec; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; diff --git a/src/main/java/com/backend/global/scheduler/SchedulerService.java b/src/main/java/com/backend/global/scheduler/SchedulerService.java index 9c733a9..256c5aa 100644 --- a/src/main/java/com/backend/global/scheduler/SchedulerService.java +++ b/src/main/java/com/backend/global/scheduler/SchedulerService.java @@ -11,8 +11,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import net.javacrumbs.shedlock.spring.annotation.SchedulerLock; - import com.backend.detailgoal.application.dto.response.DetailGoalAlarmResponse; import com.backend.detailgoal.domain.event.AlarmEvent; import com.backend.detailgoal.domain.repository.DetailGoalQueryRepository; @@ -31,14 +29,7 @@ public class SchedulerService { private final ApplicationEventPublisher applicationEventPublisher; - /* - 매일 0시 0분에 달성 기간이 지난 목표들을 보관함으로 이동시킵니다. - 서버가 Scale out되면 스케쥴러가 중복 실행될 수 있으므로 Redis 기반의 스케쥴러 락을 사용해서 하나의 스케쥴러만 실행되도록 만들었습니다. - RDBMS(MySQL)를 사용할수도 있고, Redis를 사용할 수도 있습니다. 현재 서비스에서 인증 토큰 용도로 Redis를 도입했기 때문에 추가 인프라 비용 없이 Redis를 선택했습니다. - 서비스가 성장해서 스케쥴러의 종류가 많아지고 스케일 아웃으로 서버 수도 증가하면, 스케쥴러 락을 사용하기 보다는 알림 서버를 따로 분리하는 선택을 할 것 같습니다. - - 현재는 인프라 비용 문제로 AWS 상에서 단일 서버만 운영하고 있습니다. - */ - @SchedulerLock(name = OUTDATED_GOAL_LOCK) + @Scheduled(cron = "0 0 * * * *", zone = LOCAL_TIME_ZONE) @Transactional public void storeOutDateGoal() { @@ -50,7 +41,6 @@ public void storeOutDateGoal() { /* 사용자가 지정한 시간(30분 단위)에 목표에 대한 알림을 전송합니다. */ - @SchedulerLock(name = SEND_ALARM_LOCK) @Scheduled(cron = "0 */30 * * * *", zone = LOCAL_TIME_ZONE) public void sendAlarm() { List detailGoalAlarmList = detailGoalQueryRepository.getMemberIdListDetailGoalAlarmTimeArrived( diff --git a/src/main/resources/config b/src/main/resources/config index 6dde217..a6f8fe3 160000 --- a/src/main/resources/config +++ b/src/main/resources/config @@ -1 +1 @@ -Subproject commit 6dde217b63322f8a166678c87b5ef22b02170598 +Subproject commit a6f8fe3f76fc5cb84ecf7ebe0ffa6fc09b5908cb