Skip to content

Commit

Permalink
Merge pull request #9 from potenday-project/develop
Browse files Browse the repository at this point in the history
채용공고 14일 지난 데이터 삭제 스케쥴 추가
  • Loading branch information
HwangHoYoon authored Dec 12, 2023
2 parents 3812bbf + df59ccc commit e4ac001
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/chwipoClova/ChwipoClovaApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;

@OpenAPIDefinition(servers = {@Server(url = "/", description = "Default Server URL")})
@EnableScheduling
@SpringBootApplication
public class ChwipoClovaApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
import com.chwipoClova.recruit.entity.Recruit;
import org.springframework.data.jpa.repository.JpaRepository;

import java.sql.Timestamp;
import java.util.List;

public interface RecruitRepository extends JpaRepository<Recruit, Long> {
List<Recruit> findByRegDateLessThanEqual(Timestamp baseDate);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.chwipoClova.recruit.schedule;

import com.chwipoClova.recruit.service.RecruitService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
@Slf4j
public class RecruitScheduleTask {
private final RecruitService recruitService;

@Scheduled(cron = "0 55 0 * * ?")
public void runTask() throws Exception {
log.info("recruitService Scheduled start");
recruitService.deleteBeforeRecruit();
log.info("recruitService Scheduled end");
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/chwipoClova/recruit/service/RecruitService.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.UUID;

@RequiredArgsConstructor
Expand Down Expand Up @@ -150,4 +151,16 @@ private String makeFolder() {
}
return folderPath;
}

@Transactional
public void deleteBeforeRecruit() {
Timestamp baseDate = Timestamp.valueOf(LocalDate.now().minusDays(14).atStartOfDay());
List<Recruit> recruitList = recruitRepository.findByRegDateLessThanEqual(baseDate);
if (recruitList != null) {
if (recruitList.size() > 0) {
log.info("deleteBeforeRecruit size {}, baseDate {}", recruitList.size() , baseDate);
recruitRepository.deleteAll(recruitList);
}
}
}
}

0 comments on commit e4ac001

Please sign in to comment.