Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

마감 스케줄러 작성 #36

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/kusitms/gallae/GallaeApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import jakarta.annotation.PostConstruct;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.TimeZone;


@EnableScheduling
@SpringBootApplication
public class GallaeApplication {

Expand Down
43 changes: 43 additions & 0 deletions src/main/java/kusitms/gallae/config/ProgramScheduler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package kusitms.gallae.config;


import kusitms.gallae.domain.Program;
import kusitms.gallae.repository.program.ProgramRespository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@Component // 추가
@EnableAsync
public class ProgramScheduler {



private final ProgramRespository programRespository;


@Transactional
@Scheduled(cron = "0 5 0 * * *",zone = "Asia/Seoul")
public void programFinishScheduler(){
List<Program> programList = programRespository.findAll();
//KTC로 바꾸기
LocalDateTime localDateTime = LocalDateTime.now().minusDays(1).plusHours(9);
LocalDate localDate = localDateTime.toLocalDate();
programList.forEach(program -> {
if(program.getRecruitEndDate().isBefore(localDate)) {
program.setStatus(Program.ProgramStatus.FINISH);
programRespository.save(program);
}
});

}
}
Loading