Skip to content

Commit

Permalink
refactor: 스케줄러 구성을 개선합니다. (#465)
Browse files Browse the repository at this point in the history
* refactor: 스케줄러 configuration을 추가한다.

기존 스케줄러에서 `@Component` 제거 및 수동 빈 등록으로 변경, 테스트 환경 비활성화를 위한 설정을 추가함.

* test: 스케줄러 테스트를 제거한다.

* fix: `Recruitment` 엔티티 필드 `RecruitmentApplicantCount`에 `@Embedded`를 추가한다.
  • Loading branch information
hseong3243 authored Mar 14, 2024
1 parent 80591cd commit ac77a50
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 135 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ private excludedClassFilesForReport(classDirectories) {
"**/*Request*",
"**/exception/**",
"**/Mock**",
"**/aspect/**"
"**/aspect/**",
"**/scheduler/**"
])
})
)
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/clova/anifriends/AnifriendsApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableScheduling
@SpringBootApplication
public class AnifriendsApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class Recruitment extends BaseTimeEntity {
@Column(name = "updated_at")
private LocalDateTime updatedAt;

@Embedded
private RecruitmentApplicantCount applicantCount = new RecruitmentApplicantCount(0);

public Recruitment(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.clova.anifriends.global.config;

import com.clova.anifriends.domain.notification.service.ShelterNotificationService;
import com.clova.anifriends.domain.notification.service.VolunteerNotificationService;
import com.clova.anifriends.domain.recruitment.service.RecruitmentService;
import com.clova.anifriends.global.scheduler.NotifyScheduler;
import com.clova.anifriends.global.scheduler.ServiceScheduler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;

@ConditionalOnProperty(
value = "scheduler.enabled", havingValue = "true", matchIfMissing = true
)
@EnableScheduling
@Configuration
public class SchedulerConfig {

@Bean
public NotifyScheduler notifyScheduler(
VolunteerNotificationService volunteerNotificationService,
ShelterNotificationService shelterNotificationService
) {
return new NotifyScheduler(volunteerNotificationService, shelterNotificationService);
}

@Bean
public ServiceScheduler serviceScheduler(RecruitmentService recruitmentService) {
return new ServiceScheduler(recruitmentService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import com.clova.anifriends.domain.notification.service.VolunteerNotificationService;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class NotifyScheduler {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import com.clova.anifriends.domain.recruitment.service.RecruitmentService;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class ServiceScheduler {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
import com.clova.anifriends.base.TestContainerStarter;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

@SpringBootTest
@ActiveProfiles("dev")
class AnifriendsApplicationTests extends TestContainerStarter {

@Test
void contextLoads() {
}

}
43 changes: 0 additions & 43 deletions src/test/java/com/clova/anifriends/base/BaseSchedulerTest.java

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 5 additions & 1 deletion src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ jwt:
secret: ThisIsJustTestSecretSoDontWorryItsOnlyForTest
refresh-expiry-seconds: 100000
refresh-secret: ThisIsJustTestRefreshSecretSoDontWorryItsOnlyForTest

scheduler:
enabled: false

spring:
datasource:
driver-class-name: org.h2.Driver
username: sa
url: jdbc:h2:mem:testdb
url: jdbc:h2:mem:testdb;MODE=MYSQL;
jpa:
properties:
hibernate:
Expand Down

0 comments on commit ac77a50

Please sign in to comment.