Skip to content

Commit

Permalink
Fix: 스케줄 딜레이 5분에서 1분으로 수정 (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkim1913 authored Aug 14, 2023
1 parent be0de2a commit 09b1a67
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.anywayclear.entity.Produce;
import com.anywayclear.service.AuctionService;
import com.anywayclear.service.ProduceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand All @@ -21,6 +22,7 @@

@RestController
@RequestMapping("/api/produces")
@Slf4j
//@Secured({"ROLE_CONSUMER", "ROLE_SELLER"})
public class ProduceController {
private final ProduceService produceService;
Expand Down Expand Up @@ -51,8 +53,8 @@ public ResponseEntity<ProduceResponse> getProduce(@Positive @PathVariable("id")
public ResponseEntity<MultiResponse<ProduceResponse, Produce>> getProduceList(
@RequestParam(value = "userId", required = false) String sellerId, @RequestParam(required = false, defaultValue = "all") String filter, @RequestParam List<Integer> statusNoList,
Pageable pageable, @RequestParam(required = false, defaultValue = "") String name) {
log.debug("컨트롤러 전체조회 진입");
produceService.updateProduceStatus();

return ResponseEntity.ok(produceService.getProducePage(statusNoList, pageable, name, sellerId, filter));
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/anywayclear/service/ProduceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.anywayclear.repository.AuctionRepository;
import com.anywayclear.repository.MemberRepository;
import com.anywayclear.repository.ProduceRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
Expand All @@ -21,6 +22,7 @@
import static com.anywayclear.exception.ExceptionCode.INVALID_PRODUCE_ID;

@Service
@Slf4j
public class ProduceService {
private final ProduceRepository produceRepository;
private final AuctionRepository auctionRepository;
Expand Down Expand Up @@ -65,10 +67,12 @@ public MultiResponse<ProduceResponse, Produce> getProducePage(List<Integer> stat

@Transactional
public void updateProduceStatus() {
log.debug("농산물 상태 검사 시작");
for (Produce produce : produceRepository.findByStatus(1)) {
for (Auction auction : produce.getAuctionList()) {
auctionService.checkAuctionFinished(auction.getId());
}
}
log.debug("농산물 상태 검사 종료");
}
}
5 changes: 4 additions & 1 deletion src/main/java/com/anywayclear/util/AuctionScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.anywayclear.entity.Produce;
import com.anywayclear.repository.ProduceRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -10,15 +11,17 @@

@Component
@Transactional
@Slf4j
public class AuctionScheduler {
private final ProduceRepository produceRepository;

public AuctionScheduler(ProduceRepository produceRepository) {
this.produceRepository = produceRepository;
}

@Scheduled(cron = "0 0/5 * * * ?", zone = "Asia/Seoul")
@Scheduled(cron = "0 0/1 * * * ?", zone = "Asia/Seoul")
public void updateAuctionStatus() {
log.debug("스케줄링 시작");
for (Produce produce : produceRepository.findAll()) {
if (produce.getStatus() == 0 && LocalDateTime.now().isAfter(produce.getStartDate())) {
produce.setStatus(1);
Expand Down

0 comments on commit 09b1a67

Please sign in to comment.