Skip to content

Commit 5f07acb

Browse files
committed
🐛 fix: 주문 배송 스케줄링 로직을 OrderScheduleService로 분리
1 parent 7b2706e commit 5f07acb

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

src/main/java/com/jajaja/domain/order/service/OrderCommandServiceImpl.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import org.springframework.http.HttpHeaders;
4646
import org.springframework.http.MediaType;
4747
import org.springframework.http.ResponseEntity;
48-
import org.springframework.scheduling.annotation.Async;
4948
import org.springframework.stereotype.Service;
5049
import org.springframework.transaction.annotation.Transactional;
5150
import org.springframework.web.client.HttpClientErrorException;
@@ -70,6 +69,7 @@ public class OrderCommandServiceImpl implements OrderCommandService {
7069
private final ProductCommonService productCommonService;
7170
private final CouponCommonService couponCommonService;
7271
private final PointCommandService pointCommandService;
72+
private final OrderScheduleService orderScheduleService;
7373

7474
private final TossPaymentsConfig tossPaymentsConfig;
7575
private final RestTemplateConfig restTemplateConfig;
@@ -208,7 +208,7 @@ public OrderApproveResponseDto approveOrder(Long memberId, OrderApproveRequestDt
208208
pointCommandService.addFirstPurchasePointsIfPossible(member);
209209

210210
// 30초 후 배송 시작 스케줄링
211-
scheduleShippingStart(order.getId());
211+
orderScheduleService.scheduleShippingStart(order.getId());
212212

213213
return OrderApproveResponseDto.of(order);
214214

@@ -471,18 +471,6 @@ private HttpHeaders getHeaders() {
471471
return headers;
472472
}
473473

474-
@Async("orderTaskExecutor")
475-
protected void scheduleShippingStart(Long orderId) {
476-
try {
477-
Thread.sleep(30000); // 30초 대기
478-
startShipping(orderId);
479-
} catch (InterruptedException e) {
480-
log.error("[OrderCommandService] 배송 시작 스케줄링 중단 - 주문ID: {}", orderId, e);
481-
Thread.currentThread().interrupt();
482-
} catch (Exception e) {
483-
log.error("[OrderCommandService] 배송 시작 스케줄링 실패 - 주문ID: {}", orderId, e);
484-
}
485-
}
486474

487475
@Override
488476
@Transactional
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.jajaja.domain.order.service;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.springframework.context.ApplicationContext;
6+
import org.springframework.scheduling.annotation.Async;
7+
import org.springframework.stereotype.Service;
8+
9+
@Slf4j
10+
@Service
11+
@RequiredArgsConstructor
12+
public class OrderScheduleService {
13+
14+
private final ApplicationContext applicationContext;
15+
16+
@Async("orderTaskExecutor")
17+
public void scheduleShippingStart(Long orderId) {
18+
try {
19+
log.info("[OrderScheduleService] 30초 배송 대기 시작 - 주문ID: {}", orderId);
20+
Thread.sleep(30000); // 30초 대기
21+
log.info("[OrderScheduleService] 30초 대기 완료, 배송 시작 - 주문ID: {}", orderId);
22+
23+
// 순환 참조 방지를 위해 ApplicationContext에서 직접 가져옴
24+
OrderCommandService orderCommandService = applicationContext.getBean(OrderCommandService.class);
25+
orderCommandService.startShipping(orderId);
26+
} catch (InterruptedException e) {
27+
log.error("[OrderScheduleService] 배송 시작 스케줄링 중단 - 주문ID: {}", orderId, e);
28+
Thread.currentThread().interrupt();
29+
} catch (Exception e) {
30+
log.error("[OrderScheduleService] 배송 시작 스케줄링 실패 - 주문ID: {}", orderId, e);
31+
}
32+
}
33+
}

src/main/java/com/jajaja/domain/team/service/TeamCommandService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.jajaja.domain.team.dto.response.TeamCreateResponseDto;
44

55
public interface TeamCommandService {
6-
TeamCreateResponseDto createTeam(Long memberId, Long productId);
6+
TeamCreateResponseDto createTeam(Long memberId, Long orderId);
77
void joinTeam(Long memberId, Long teamId);
88
void joinTeamInCarts(Long memberId, Long productId);
99
}

0 commit comments

Comments
 (0)